如何使用 `mean_se()` 函数来计算置信区间?

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

How to use the `mean_se()` function to calculate confidence intervals?

问题

我想以编程方式创建95%置信区间。我如何设置geom_errorbar()中的mean_semult参数?

mtcars %>%
  ggplot(aes(factor(cyl), hp)) +
  geom_bar(stat = "summary", fun = mean, na.rm = TRUE)
  geom_errorbar(stat = "summary", width = .3)
英文:

I want to programmatically create 95% confidence intervals. How can I set the mult argument of mean_se in geom_errorbar()?

mtcars %>% 
  ggplot(aes(factor(cyl), hp)) +
  geom_bar(stat = "summary", fun = mean, na.rm = TRUE)
  geom_errorbar(stat = "summary", width = .3)

答案1

得分: 1

以下是您要翻译的内容:

library(ggplot2)
  ggplot(mtcars, aes(factor(cyl), hp)) +
  geom_bar(stat = "summary", fun = mean, na.rm = TRUE) +
  stat_summary(
    fun.data = "mean_se",
    fun.args = list(mult = 1.96),
    geom = "errorbar",
    width = 0.3
  )

如何使用 `mean_se()` 函数来计算置信区间?

Created on 2023-02-15 with reprex v2.0.2

英文:

As a start

library(ggplot2)
  ggplot(mtcars, aes(factor(cyl), hp)) +
  geom_bar(stat = "summary", fun = mean, na.rm = TRUE) +
  stat_summary(
    fun.data = "mean_se",
    fun.args = list(mult = 1.96),
    geom = "errorbar",
    width = 0.3
  )

如何使用 `mean_se()` 函数来计算置信区间?

<sup>Created on 2023-02-15 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年2月16日 13:11:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75468078.html
匿名

发表评论

匿名网友

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

确定