Biology Reference
In-Depth Information
(f) > quit(save = "yes")
1.5 Consider the gaussian.test data set included in bnlearn.
(a) Print the column names.
(b) Print the range and the quartiles of each variable.
(c) Print all the observations for which A falls in the interval
[
3
,
4
]
and B in
.
(d) Sample 50 rows without replacement.
(e) Draw a bootstrap sample (e.g., sample 5000 observations with replacement)
and compute the mean of each variable.
(f) Standardize each variable.
( ,−
5
] [
10
, )
(a) > colnames(gaussian.test)
> names(gaussian.test)
(b) > for (var in names(gaussian.test))
+ print(range(gaussian.test[, var]))
> for (var in names(gaussian.test))
+ print(quantile(gaussian.test[, var],
+ probs = (1:3)/4))
(c) > condA = (gaussian.test[, "A"] >= 3) &
+ (gaussian.test[, "A"] <= 4)
> condB = (gaussian.test[, "B"] <= -4) |
+ (gaussian.test[, "B"] >= 4)
> gaussian.test[condA & condB, ]
(d) > gaussian.test[sample(50, replace = FALSE), ]
(e) > colMeans(gaussian.test[
+ sample(5000, replace = TRUE), ])
(f) > scale(gaussian.test)
1.6
Generate a data frame with 100 observations for the following variables:
(a) A categorical variable with two levels, low and high . The first 50 obser-
vations should be set to low , the others to high .
(b) A categorical variable with two levels, good and bad , nested within the
first variable, i.e., the first 25 observations should be set to good , the second
25 to bad ,andsoon.
(c) A continuous, numerical variable following a Gaussian distribution with
mean 2 and variance 4 when the first variable is equal to low and with
mean 4 and variance 1 if the first variable is equal to high .
In addition, compute the standard deviation of the last variable for each con-
figuration of the first two variables. The variables can be generated as follows:
(a) > A = factor(c(rep("low", 50), rep("high", 50)),
+ levels = c("low", "high"))
(b) > nesting = c(rep("good", 25), rep("bad", 25))
> B = factor(rep(nesting, 2),
+
levels = c("good", "bad"))
Search WWH ::




Custom Search