英文:
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 <- 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 <- c(1, 1.2, 0.8, 0.9)
cumulative_mean <- cummean(outcome)
# Create a data frame with the cumulative means and their indices
df <- 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("Index") +
ylab("Cumulative Mean") +
ggtitle("Cumulative Mean Plot")+
theme_minimal()
And here is base R version:
plot(cumulative_mean, type = "p", xlab = "Step", ylab = "Cumulative Mean")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论