── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.0 ✔ readr 2.1.6
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.2 ✔ tibble 3.3.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.2
✔ purrr 1.2.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Step 2: Read in the data
mh <-read_csv("MillerHadenData.csv")
Rows: 25 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (5): Participant, Abil, IQ, Home, TV
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ggplot (mh, aes (x = TV, y = Home)) +geom_point() +geom_smooth(method ="lm", se =FALSE) +theme_bw() +labs(x ="Time spend reading at home", y ="Time spend watching TV at home")
`geom_smooth()` using formula = 'y ~ x'
Step 4: Conduct a correlation analysis
results <-cor.test(mh$Home, mh$TV, method ="pearson", alternative ="two.sided") %>%tidy()results
A Pearson’s correlation coefficient was used to assess the relationship between time spent watching TV and time spent reading at home. There was a significant negative correlation, r(23) = -.65, p < .001. As time spent watching TV increased, time spent reading at home decreased.
Lab activity 3: Hazardours alcohol use and impulsivity.
Step 1: Read in the data
data <-read_csv("alcoholUse_Impulsivity.csv")
Rows: 20 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (3): participant, hau, imp
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Step 2: Plot the relationship between hazard alcohol use and impulsivity using a scatterplot and a line of best fit
ggplot(data, aes(x = hau, y = imp)) +geom_point() +geom_smooth(method ="lm", se =FALSE) +theme_bw() +labs(x ="Hazardous Alcohol Use", y ="Impulsivity")
`geom_smooth()` using formula = 'y ~ x'
Step 3: Conduct a correlation analysis, using Pearson’s r
results <-cor.test(data$hau, data$imp, method ="pearson", alternative ="two.sided") %>%tidy()results
A Pearson’s correlation coefficient was used to assess the relationship alcohol use and impulsivity. There was a significant positive correlation, r(18) = .54, p < .014. As alcohol use increased, impulsivity also increased.