r - R工作室公平骰子的概率
问题描述
考虑一个实验,该实验包括投掷 100 个公平骰子并将单个骰子的结果相加。计算平均结果?
我如何在 R studio 中做到这一点,以及如何在 Rstudio 中绘制概率分布图
解决方案
我只是展示一个例子
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))
推荐阅读
- python - 为什么这个浮点转换异常没有被很好地捕捉到?
- r - RcppEigen 作为参数失败
- c - 如何以递归方式从当前调用访问先前调用的变量值
- angular - 如何在翻译开始之前将 i18n 键从父组件传递给子组件?
- javascript - 幻灯片功能和 Internet Explorer 11
- python-3.x - 条形图未显示折线图
- reactjs - 使用 rxjs-compat v6.3.3 从 rxjs v5.5.6 升级到 rxjs v6.3.3
- database - URI 图像 - 数据库列 v/s 类文件
- ruby-on-rails - Rails 5 - 通过 UJS / 远程创建嵌套资源:是吗?
- react-native-navigation - Wix react-native-navigation v2 动态选项卡