z_scores <- seq(-3, 3, by = .1) # First I'll make a vector of Z-scores
# Let's make a vector of the values the function takes given those Z-scores.
# Remember for dnorm the default value for mean is 0 and for sd is 1.
dvalues <- dnorm(z_scores)
# Now we'll plot these values
plot(dvalues, # Plot where y = values and x = index of the value in the vector
xaxt = "n", # Don't label the x-axis
type = "l", # Make it a line plot
main = "pdf of the Standard Normal",
xlab= "Z-score")
# These commands label the x-axis
axis(1, at=which(dvalues == dnorm(0)), labels=c(0))
axis(1, at=which(dvalues == dnorm(1)), labels=c(-1, 1))
axis(1, at=which(dvalues == dnorm(2)), labels=c(-2, 2))
# define the number of rolls
n <- 100
# sample with replacement draws n times from the numbers 1:6
dice <- sample(1:6, n, replace=TRUE)
# calculate the sum of simluated dice rolls
dice_sum <- sum(dice)
# calculate the average outcome
result <- dice_sum/n
# draw a histogram with a density plot
hist(dice, breaks=seq(0,6, 0.5), probability = TRUE, col = rainbow(12))
lines(density(dice))
2条答案
按热度按时间fd3cxomn1#
我只是举个例子
X表示正态分布的pdf的自变量,把x看作Z分数也很有用,让我用dnorm来表示正态分布的pdf,
字符串
的数据
0sgqnhkj2#
这应该能让你给予一个解决问题的开始。
字符串