根据正态分布创建具有随机值的矩阵
create a matrix with random values based on a normal distrubition
我们取以下数据:
Mini <- c(8500, 11000, 10500, 12000, 9500, 10500, 12000, 11500)
Kleinwagen <- c(8500, 10500, 10500, 10500, 12500, 12000, 13000, 13500)
Kompatklass <- c(11000, 13000, 12500, 13000, 13500, 15500, 15500, 17500)
minivans <- c(6000, 11500, 10500, 13000, 13000, 14000, 14500, 19000)
sportswagen <- c(12000, 12000, 14000, 18000, 16000, 17000, 26000, 21500)
utilities <- c(7500, 11000, 11500, 11000, 12000, 16500, 16500, 21500)
mittleklass <- c(11000, 12000, 14000, 14000, 15000, 17500, 28000, 26000)
oberemittle <- c(11000, 13500, 14000, 14500, 17000, 20000, 25000, 30500)
bigvans <- c(13000, 12500, 16000, 15000, 16000, 17000, 18500, 37500)
Dist.table <- t(data.frame(Mini, Kleinwagen, Kompatklass, minivans, sportswagen, utilities, mittleklass, oberemittle, bigvans))
现在我假设每个值都是平均值。我还假设标准差恒定为 0.7%
如果我使用:
b <- rnorm(1, mean = Dist.table[1, 1], sd = Dist.table[1, 1] * 0.007)
我为 [1,1] 生成一个随机数。
但我想创建一个完整的随机变量矩阵
怎么样:
matrix(rnorm(prod(dim(Dist.table)), mean = Dist.table, sd = Dist.table * 0.007), nrow = nrow(Dist.table))
我们取以下数据:
Mini <- c(8500, 11000, 10500, 12000, 9500, 10500, 12000, 11500)
Kleinwagen <- c(8500, 10500, 10500, 10500, 12500, 12000, 13000, 13500)
Kompatklass <- c(11000, 13000, 12500, 13000, 13500, 15500, 15500, 17500)
minivans <- c(6000, 11500, 10500, 13000, 13000, 14000, 14500, 19000)
sportswagen <- c(12000, 12000, 14000, 18000, 16000, 17000, 26000, 21500)
utilities <- c(7500, 11000, 11500, 11000, 12000, 16500, 16500, 21500)
mittleklass <- c(11000, 12000, 14000, 14000, 15000, 17500, 28000, 26000)
oberemittle <- c(11000, 13500, 14000, 14500, 17000, 20000, 25000, 30500)
bigvans <- c(13000, 12500, 16000, 15000, 16000, 17000, 18500, 37500)
Dist.table <- t(data.frame(Mini, Kleinwagen, Kompatklass, minivans, sportswagen, utilities, mittleklass, oberemittle, bigvans))
现在我假设每个值都是平均值。我还假设标准差恒定为 0.7%
如果我使用:
b <- rnorm(1, mean = Dist.table[1, 1], sd = Dist.table[1, 1] * 0.007)
我为 [1,1] 生成一个随机数。
但我想创建一个完整的随机变量矩阵
怎么样:
matrix(rnorm(prod(dim(Dist.table)), mean = Dist.table, sd = Dist.table * 0.007), nrow = nrow(Dist.table))