测试数据
data <- data. frame(label = sample(LETTERS[1:5],500,replace = T), value = rnorm(500))
1、根据公式计算
data %>% group_by(label) %>% summarise(mean = mean(value),sd= sd(value),se = sd(value)/sqrt(n()))
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# A tibble: 5 × 4
label mean sd se
<chr> <dbl> <dbl> <dbl>
1 A 0.148 1.01 0.108
2 B 0.0789 0.946 0.0936
3 C -0.0888 1.02 0.0998
4 D -0.102 0.958 0.0983
5 E 0.0893 0.823 0.0785
2、rstatix 软件包计算各数据指标(计算精度偏低)
data %>% group_by(label) %>% rstatix::get_summary_stats(value,show = c("mean", "sd","se")) #### 精度偏低
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# A tibble: 5 × 6
label variable n mean sd se
<chr> <fct> <dbl> <dbl> <dbl> <dbl>
1 A value 88 0.148 1.01 0.108
2 B value 102 0.079 0.946 0.094
3 C value 105 -0.089 1.02 0.1
4 D value 95 -0.102 0.958 0.098
5 E value 110 0.089 0.823 0.078
3、plotrix 软件包计算标准误
data %>% group_by(label) %>% summarise(mean = mean(value),sd= sd(value),se = plotrix::std.error(value))
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# A tibble: 5 × 4
label mean sd se
<chr> <dbl> <dbl> <dbl>
1 A 0.148 1.01 0.108
2 B 0.0789 0.946 0.0936
3 C -0.0888 1.02 0.0998
4 D -0.102 0.958 0.0983
5 E 0.0893 0.823 0.0785
网友评论