devAskNewPage(ask = TRUE)
# Generate and print multivariate normal datasets with diagonal
# variance-covariance matrices.
n <- c(75, 100, 125, 150, 175)
Theta <- new("RNGMIX.Theta", c = 5, pdf = rep("normal", 4))
a.theta1(Theta, 1) <- c(10, 12, 10, 12)
a.theta1(Theta, 2) <- c(8.5, 10.5, 8.5, 10.5)
a.theta1(Theta, 3) <- c(12, 14, 12, 14)
a.theta1(Theta, 4) <- c(13, 15, 7, 9)
a.theta1(Theta, 5) <- c(7, 9, 13, 15)
a.theta2(Theta, 1) <- c(1, 1, 1, 1)
a.theta2(Theta, 2) <- c(1, 1, 1, 1)
a.theta2(Theta, 3) <- c(1, 1, 1, 1)
a.theta2(Theta, 4) <- c(2, 2, 2, 2)
a.theta2(Theta, 5) <- c(3, 3, 3, 3)
simulated <- RNGMIX(Dataset.name = paste("simulated_", 1:25, sep = ""),
rseed = -1,
n = n,
Theta = a.Theta(Theta))
simulated
plot(simulated, pos = 22, nrow = 2, ncol = 3)
# Generate and print multivariate normal datasets with unrestricted
# variance-covariance matrices.
n <- c(200, 50, 50)
Theta <- new("RNGMVNORM.Theta", c = 3, d = 3)
a.theta1(Theta, 1) <- c(0, 0, 0)
a.theta1(Theta, 2) <- c(-6, 3, 6)
a.theta1(Theta, 3) <- c(6, 6, 4)
a.theta2(Theta, 1) <- c(9, 0, 0, 0, 4, 0, 0, 0, 1)
a.theta2(Theta, 2) <- c(4, -3.2, -0.2, -3.2, 4, 0, -0.2, 0, 1)
a.theta2(Theta, 3) <- c(4, 3.2, 2.8, 3.2, 4, 2.4, 2.8, 2.4, 2)
simulated <- RNGMIX(model = "RNGMVNORM",
Dataset.name = paste("simulated_", 1:2, sep = ""),
rseed = -1,
n = n,
Theta = a.Theta(Theta))
simulated
plot(simulated, pos = 2, nrow = 3, ncol = 1)
# Generate and print multivariate mixed continuous-discrete datasets.
n <- c(400, 100, 500)
Theta <- new("RNGMIX.Theta", c = 3, pdf = c("lognormal", "Poisson", "binomial", "Weibull"))
a.theta1(Theta, 1) <- c(1, 2, 10, 2)
a.theta1(Theta, 2) <- c(3.5, 10, 10, 10)
a.theta1(Theta, 3) <- c(2.5, 15, 10, 25)
a.theta2(Theta, 1) <- c(0.3, NA, 0.9, 3)
a.theta2(Theta, 2) <- c(0.2, NA, 0.1, 7)
a.theta2(Theta, 3) <- c(0.4, NA, 0.7, 20)
simulated <- RNGMIX(Dataset.name = paste("simulated_", 1:5, sep = ""),
rseed = -1,
n = n,
Theta = a.Theta(Theta))
simulated
plot(simulated, pos = 4, nrow = 2, ncol = 3)
# Generate and print univariate mixed Weibull dataset.
n <- c(75, 100, 125, 150, 175)
Theta <- new("RNGMIX.Theta", c = 5, pdf = "Weibull")
a.theta1(Theta) <- c(12, 10, 14, 15, 9)
a.theta2(Theta) <- c(2, 4.1, 3.2, 7.1, 5.3)
simulated <- RNGMIX(Dataset.name = "simulated",
rseed = -1,
n = n,
Theta = a.Theta(Theta))
simulated
plot(simulated, pos = 1)
# Generate and print multivariate normal datasets with unrestricted
# variance-covariance matrices.
# Set dimension, dataset size, number of components and seed.
d <- 2; n <- 1000; c <- 10; set.seed(123)
# Component weights are generated.
w <- runif(c, 0.1, 0.9); w <- w / sum(w)
# Set range of means and rang of eigenvalues.
mu <- c(-100, 100); lambda <- c(1, 100)
# Component means and variance-covariance matrices are calculated.
Mu <- list(); Sigma <- list()
for (l in 1:c) {
Mu[[l]] <- runif(d, mu[1], mu[2])
Lambda <- diag(runif(d, lambda[1], lambda[2]), nrow = d, ncol = d)
P <- svd(matrix(runif(d * d, -1, 1), nc = d))$u
Sigma[[l]] <- P
}
# Numbers of observations are calculated and component means and
# variance-covariance matrices are stored.
n <- round(w * n); Theta <- list()
for (l in 1:c) {
Theta[[paste0("pdf", l)]] <- rep("normal", d)
Theta[[paste0("theta1.", l)]] <- Mu[[l]]
Theta[[paste0("theta2.", l)]] <- as.vector(Sigma[[l]])
}
# Dataset is generated.
simulated <- RNGMIX(model = "RNGMVNORM", Dataset.name = "mvnorm_1",
rseed = -1, n = n, Theta = Theta)
plot(simulated)
# Generate and print bivariate mixed uniform-Gumbel dataset.
n <- c(100, 150)
Theta <- new("RNGMIX.Theta", c = 2, pdf = c("uniform", "Gumbel"))
a.theta1(Theta, l = 1) <- c(2, 10)
a.theta2(Theta, l = 1) <- c(10, 2.3)
a.theta3(Theta, l = 1) <- c(NA, 1.0)
a.theta1(Theta, l = 2) <- c(10, 50)
a.theta2(Theta, l = 2) <- c(30, 4.2)
a.theta3(Theta, l = 2) <- c(NA, -1.0)
simulated <- RNGMIX(Dataset.name = paste("simulated_", 1, sep = ""),
rseed = -1,
n = n,
Theta = a.Theta(Theta))
plot(simulated)
Run the code above in your browser using DataLab