Created
March 21, 2023 05:26
-
-
Save mcfrank/6066d428dba57109706cc23011687cf5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "mtcars example markdown" | |
author: "Mike Frank" | |
date: "2023-03-21" | |
output: | |
html_document: | |
toc: true | |
toc_float: true | |
--- | |
```{r echo=FALSE} | |
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, | |
message = FALSE, sanitize = TRUE) | |
``` | |
```{r} | |
library(tidyverse) | |
``` | |
# The `mtcars` dataset | |
```{r} | |
knitr::kable(mtcars) | |
``` | |
# Analysis | |
## Visualization | |
```{r} | |
ggplot(mtcars, aes(x = mpg, y = hp, col = as.factor(cyl))) + | |
geom_point() + | |
geom_smooth(method = "lm") | |
``` | |
## Statistical testing | |
```{r} | |
cars_t <- with(mtcars, | |
t.test(mpg[cyl == 8], | |
mpg[cyl == 4]) ) | |
# cars_t$statistic | |
# cars_t$parameter | |
# cars_t$p.value | |
``` | |
There are `r sum(mtcars$cyl == 8)` cars in the dataset with 8 cylinders, and `r sum(mtcars$cyl == 4)` cars with 4 cylinders. | |
Cars with 8 cylinders have significantly lower gas mileage than cars with 4 cylinders (t(`r round(cars_t$parameter,2)`) = `r round(cars_t$statistic,2)`, p = `r round(cars_t$p.value,6)`). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment