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

4) Save and Knit to HTML

  1. Save file: File → Save (or Ctrl/Cmd+S) — name it: motor_trend_report.Rmd
  2. Click the Knit button (the ball of yarn icon) at the top of the script editor.
    • RStudio will run every chunk and produce motor_trend_report.html and open it in Viewer.
  3. Inspect the Executive summary and the Model outputs — copy the numeric estimate and CI into the executive summary sentence if you want exact numbers there.

5) If you get package or code errors


6) Make the report ~2 pages


7) Publish & share (RPubs — easiest)

  1. After Knit, the HTML opens in Viewer. On the top-right of Viewer click PublishRPubs.
  2. Log in (create an account if needed).
  3. Add a title and click Publish.
  4. Copy the generated RPubs link — that’s what you submit for the presentation/report.

If RPubs button is missing, click the small gear icon in Viewer or use rpubsUpload() from the rsconnect package (I can show exact command if needed).


8) Optional: Push to GitHub (for graders who want code)

  1. Create a GitHub repo (e.g., motor-trend-report).
  2. Add these files: motor_trend_report.Rmd and the knitted motor_trend_report.html.
  3. Commit & push (or use GitHub web UI → Upload files).
  4. Paste the repo URL in your submission.

9) What to write in the short report (copy-paste language)

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.


10) Quick troubleshooting cheatsheet


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).