一直在练习 mtcars 数据集。
我用线性模型创建了这个图。
library(tidyverse)
library(tidymodels)
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
geom_point() + geom_smooth(method = 'lm')
Run Code Online (Sandbox Code Playgroud)
然后我将数据帧转换为长数据帧,以便我可以尝试 facet_wrap。
mtcars_long_numeric <- mtcars %>%
select(mpg, disp, hp, drat, wt, qsec)
mtcars_long_numeric <- pivot_longer(mtcars_long_numeric, names_to = 'names', values_to = 'values', 2:6)
Run Code Online (Sandbox Code Playgroud)
现在我想了解一些关于 geom_smooth 的标准误差,看看我是否可以使用引导生成置信区间。
我在此链接的 RStudio 整洁模型文档中找到了此代码。
boots <- bootstraps(mtcars, times = 250, apparent = TRUE)
boots
fit_nls_on_bootstrap <- function(split) {
lm(mpg ~ wt, analysis(split))
}
boot_models <-
boots %>%
dplyr::mutate(model = map(splits, fit_nls_on_bootstrap),
coef_info = …
Run Code Online (Sandbox Code Playgroud)