In the code below, I first create 10 different class tools, and then use the tools to get random values from these tools. The code is identical for the two scenarios, but you will need to adjust the variance within and between classes to get the desired results.
Scenario 1:
10 ( , ). , .
library(MASS)
n <- 20
classes <- 10
mean <- 100
var.between <- 25
var.within <- 225
covmatrix1 <- matrix(c(var.between,0,0,var.between), nrow=2)
means <- mvrnorm(classes, c(100,100), Sigma=covmatrix1)
covmatrix2 <- matrix(c(var.within,0,0,var.within), nrow=2)
class <- NULL
values <- NULL
for (i in 1:10) {
temp <- mvrnorm(n, c(means[i], means[i+classes]), Sigma=covmatrix2)
class <- c(class, rep(i, n))
values <- c(values, temp)
}
valuematrix <- matrix(values, nrow=(n*classes))
data <- data.frame (class, valuematrix)
plot(data$X1, data$X2)
, , , :
covmatrix <- matrix(c(225, 0, 0, 225), nrow=2)
values <- matrix(mvrnorm(200, c(100,100), Sigma=covmatrix), nrow=200)
2:
, , . var.between 500 var.within 25, :
n <- 20
classes <- 10
mean <- 100
var.between <- 500
var.within <- 25
covmatrix1 <- matrix(c(var.between,0,0,var.between), nrow=2)
means <- mvrnorm(classes, c(100,100), Sigma=covmatrix1)
covmatrix2 <- matrix(c(var.within,0,0,var.within), nrow=2)
class <- NULL
values <- NULL
for (i in 1:10) {
temp <- mvrnorm(n, c(means[i], means[i+classes]), Sigma=covmatrix2)
class <- c(class, rep(i, n))
values <- c(values, temp)
}
valuematrix <- matrix(values, nrow=(n*classes))
data <- data.frame (class, valuematrix)
plot(data$X1, data$X2)
, .
, !