首页 > 解决方案 > R工作室公平骰子的概率

问题描述

考虑一个实验,该实验包括投掷 100 个公平骰子并将单个骰子的结果相加。计算平均结果?

我如何在 R studio 中做到这一点,以及如何在 Rstudio 中绘制概率分布图

标签: r

解决方案


我只是展示一个例子

X 表示正态分布的 pdf 的自变量,将 x 视为 Z 分数也很有用。让我通过用 dnorm 绘制正态分布的 pdf 来向您展示我的意思

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))

在此处输入图像描述


推荐阅读