R 多次取样,并使用趋势线计算平均值的标准偏差和标准误差

R 多次取样,并使用趋势线计算平均值的标准偏差和标准误差,r,random,sampling,R,Random,Sampling,假设我有以下数据: df1我不确定您在这里试图做什么,但这是第一次尝试,我认为您需要: library(ggplot2) my_theme = theme_minimal() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"), legend.title = element_blank()) df1

假设我有以下数据:


df1我不确定您在这里试图做什么,但这是第一次尝试,我认为您需要:

library(ggplot2)

my_theme = theme_minimal() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"), legend.title = element_blank())

df1 <- rnorm(100000, 20, 5)

df <- data.frame(sample_size = c(25,50,100,200,300,400,500,600))

samples <- lapply(df$sample_size, function (x) {sample(df1, x)})

df$std <- sapply(samples, sd)
df$se <- sapply(samples, function(x) {sd(x)/sqrt(length(x))})


ggplot(data = df) + geom_point(aes(x = sample_size, y = std, colour = "std")) + geom_point(aes(x = sample_size, y = se, colour = "se")) + 
    geom_smooth(aes(x = sample_size, y = std), method = "lm",) +
    geom_smooth(aes(x = sample_size, y = se), method = "lm") + my_theme
库(ggplot2)
my_theme=theme_minimal()+theme(panel.grid.major=element_blank()、panel.grid.minor=element_blank()、axis.line=element_line(color=“black”)、legend.title=element_blank()

df1为什么标准偏差会随着样本量的增加而增加?我假设你要找的标准偏差是单个样本的标准偏差?哦,抱歉。为什么会减少?由于样品不同,标准偏差会发生变化,但不一定会减小。但是,它将接近生成样本的分布的标准偏差(即5)。好吧,我现在非常不确定您在寻找什么。您是否希望在
C=(2525,501002000300400500600)
中为每种尺寸提供50个样品?如果是这样的话,平均值的标准偏差和标准误差在哪里适合呢?好的,那么我建议替换
df