在模拟次数上绘制均值/方差

huangapple go评论64阅读模式
英文:

Plot mean/variance over number of simulations

问题

Unfortunately I don't know the name of this kind of plot/calculation method: There is an outcome from the single 'runs' from a MCS. To show convergence I want to plot the mean and/or variance of every adding step in R. E.g.

outcome <- c(1,1.2,0.8,0.9)

In the graph: mean = 1 over step 1, mean = 1.1 over step 2... What is the standard method? How to perform this growing number of means/variance? Thanks!

英文:

Unfortunately I don't know the name of this kind of plot/calculation method:
There is an outcome from the single'runs' from a MCS. To show converence I want to plot the mean and/or variance of every adding step in R.
E.g.

outcome &lt;- c(1,1.2,0.8,0.9)

In the graph: mean = 1 over step 1, mean = 1.1 over step 2... What is the standard method? How to perform this growing number of means/variance?
Thanks!

答案1

得分: 1

以下是代码部分的中文翻译:

outcome <- c(1, 1.2, 0.8, 0.9)
cumulative_mean <- cummean(outcome)

# 创建一个包含累积均值和它们的索引的数据框
df <- data.frame(cumulative_mean = cumulative_mean, index = 1:length(cumulative_mean))

# 绘制累积均值图
ggplot(df, aes(x = index, y = cumulative_mean)) +
  geom_point() +
  xlab("索引") +
  ylab("累积均值") +
  ggtitle("累积均值图")+
  theme_minimal()

另外,这是基础的R版本:

plot(cumulative_mean, type = "p", xlab = "步骤", ylab = "累积均值")
英文:

Ok. you are looking for cumulative mean:

Here is a ggplot version:

outcome &lt;- c(1, 1.2, 0.8, 0.9)
cumulative_mean &lt;- cummean(outcome)

# Create a data frame with the cumulative means and their indices
df &lt;- data.frame(cumulative_mean = cumulative_mean, index = 1:length(cumulative_mean))

# Plot the cumulative means
ggplot(df, aes(x = index, y = cumulative_mean)) +
  geom_point() +
  xlab(&quot;Index&quot;) +
  ylab(&quot;Cumulative Mean&quot;) +
  ggtitle(&quot;Cumulative Mean Plot&quot;)+
  theme_minimal()

在模拟次数上绘制均值/方差

And here is base R version:

plot(cumulative_mean, type = &quot;p&quot;, xlab = &quot;Step&quot;, ylab = &quot;Cumulative Mean&quot;)

在模拟次数上绘制均值/方差

huangapple
  • 本文由 发表于 2023年2月19日 00:50:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75494853.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定