mtcars <- mtcars %>% mutate(am = factor(am, labels = c("Automatic", "Manual")))
# summary by transmission
mtcars %>% group_by(am) %>% summarise(n = n(), mean_mpg = mean(mpg), sd_mpg = sd(mpg))
## # A tibble: 2 x 4
## am n mean_mpg sd_mpg
## <fct> <int> <dbl> <dbl>
## 1 Automatic 19 17.1 3.83
## 2 Manual 13 24.4 6.17
# boxplot
ggplot(mtcars, aes(x = am, y = mpg, fill = am)) +
geom_boxplot() +
labs(title = "MPG by Transmission Type", x = "Transmission", y = "MPG") +
theme_minimal() + theme(legend.position = "none")
fit_unadj <- lm(mpg ~ am, data = mtcars)
fit_adj <- lm(mpg ~ am + wt + hp, data = mtcars)
# tidy outputs
tidy_unadj <- broom::tidy(fit_unadj, conf.int = TRUE)
tidy_adj <- broom::tidy(fit_adj, conf.int = TRUE)
tidy_unadj
## # A tibble: 2 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 17.1 1.12 15.2 1.13e-15 14.9 19.4
## 2 amManual 7.24 1.76 4.11 2.85e- 4 3.64 10.8
tidy_adj
## # A tibble: 4 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 34.0 2.64 12.9 2.82e-13 28.6 39.4
## 2 amManual 2.08 1.38 1.51 1.41e- 1 -0.736 4.90
## 3 wt -2.88 0.905 -3.18 3.57e- 3 -4.73 -1.02
## 4 hp -0.0375 0.00961 -3.90 5.46e- 4 -0.0572 -0.0178
# report the coefficient for Manual (reference = Automatic)
coef_unadj <- tidy_unadj %>% filter(term == "amManual")
coef_adj <- tidy_adj %>% filter(term == "amManual")
coef_unadj; coef_adj
## # A tibble: 1 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 amManual 7.24 1.76 4.11 0.000285 3.64 10.8
## # A tibble: 1 x 7
## term estimate std.error statistic p.value conf.low conf.high
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 amManual 2.08 1.38 1.51 0.141 -0.736 4.90
par(mfrow = c(2,2))
plot(fit_adj)
confint(fit_adj)["amManual", ]
## 2.5 % 97.5 %
## -0.7357587 4.9031790
summary(fit_adj)$coefficients["amManual", c("Estimate","Std. Error","t value","Pr(>|t|)")]
## Estimate Std. Error t value Pr(>|t|)
## 2.0837101 1.3764202 1.5138620 0.1412682
File → Save (or Ctrl/Cmd+S) — name it: motor_trend_report.Rmdmotor_trend_report.html and open it in Viewer.install.packages("packagename") in Console, then re-Knit.File → Knit to PDF (requires LaTeX) — not necessary.motor-trend-report).motor_trend_report.Rmd and the knitted motor_trend_report.html.Use the executive summary I suggested earlier, then fill in the exact numbers after you knit and see them. Keep main body ~1–2 pages; put long model outputs in Appendix.
Example conclusion sentence (paste and edit after you see numbers): > After adjusting for weight and horsepower, manual transmissions are associated with an estimated 1.8 MPG higher fuel efficiency compared to automatics (95% CI: 0.5 to 3.0 MPG; p = 0.01). Residual diagnostics show no serious violations. Therefore, manual transmissions appear modestly better for MPG, though much of the raw difference is explained by vehicle weight and horsepower.
library() missing → run install.packages("...").fig.width and fig.height in chunk options, e.g. {r, fig.width=6, fig.height=3}.rsconnect::rpubsUpload() if necessary.If you want, I’ll do one of these next right now (pick one):
A) Give the exact filled executive summary with numbers after I run the code (you paste output),
B) Produce a zipped folder of files you can upload to GitHub (I’ll show commands), or
C) Walk you step-by-step through publishing to RPubs (I’ll list exact clicks and expected screens).