1 Loading Libraries

library(psych) # for the describe() command
library(broom) # for the augment() command
library(ggplot2) # to visualize our results
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha

2 Importing Data

# import the dataset you cleaned previously
# this will be the dataset you'll use throughout the rest of the semester
# use EAMMi2 data
d <- read.csv(file="data/mydata.csv", header=T)

3 State Your Hypothesis

We hypothesize that Agreeableness (measured by the BFI) will significantly predict reported Pandemic related Anxiety (measured by the PAS), and that the relationship will be negative.

4 Check Your Variables

# you only need to check the variables you're using in the current analysis
# although you checked them previously, it's always a good idea to look them over again and be sure that everything is correct
str(d)
## 'data.frame':    1009 obs. of  6 variables:
##  $ trans    : chr  "no" "no" "no" "no" ...
##  $ age      : chr  "1 under 18" "1 under 18" "4 between 36 and 45" "4 between 36 and 45" ...
##  $ big5_agr : num  4.33 6.67 4.67 6.67 5.33 ...
##  $ big5_ext : num  1.67 6 5 5.67 4 ...
##  $ rse      : num  1.6 3.9 1.7 2.4 1.8 3.5 3 3.5 2.5 3.4 ...
##  $ pas_covid: num  4.56 3.33 4.22 3.56 4.56 ...
# you can use the describe() command on an entire dataframe (d) or just on a single variable
describe(d)
##           vars    n mean   sd median trimmed  mad min max range  skew kurtosis
## trans*       1 1009 1.10 0.39   1.00    1.00 0.00   1   3     2  4.08    15.93
## age*         2 1009 2.07 1.64   1.00    1.84 0.00   1   5     4  1.01    -0.83
## big5_agr     3 1009 5.01 1.12   5.00    5.05 0.99   1   7     6 -0.39    -0.03
## big5_ext     4 1009 4.34 1.45   4.33    4.38 1.48   1   7     6 -0.23    -0.77
## rse          5 1009 2.65 0.71   2.70    2.67 0.74   1   4     3 -0.20    -0.74
## pas_covid    6 1009 3.24 0.68   3.22    3.26 0.66   1   5     4 -0.23     0.12
##             se
## trans*    0.01
## age*      0.05
## big5_agr  0.04
## big5_ext  0.05
## rse       0.02
## pas_covid 0.02
# also use histograms to examine your continuous variables
hist(d$big5_agr)

hist(d$pas_covid)

# last, use scatterplots to examine your continuous variables together
plot(d$big5_agr,d$pas_covid)

5 Run a Simple Regression

# to calculate standardized coefficients, we have to standardize our IV
d$efficacy <- scale(d$big5_agr, center=T, scale=T)
d$swb <- scale(d$pas_covid, center=T, scale=T)

# use the lm() command to run the regression
# dependent/outcome variable on the left, idependent/predictor variable on the right
reg_model <- lm(pas_covid ~ big5_agr, data = d)

6 Check Your Assumptions

6.1 Simple Regression Assumptions

  • Should have two measurements for each participant
  • Variables should be continuous and normally distributed
  • Outliers should be identified and removed
  • Relationship between the variables should be linear
  • Residuals should be normal and have constant variance note: we will not be evaluating whether our data meets these assumptions in this lab/homework – we’ll come back to them next week when we talk about multiple linear regression

6.2 Create plots and view residuals

model.diag.metrics <- augment(reg_model)

ggplot(model.diag.metrics, aes(x = big5_agr, y = pas_covid)) +
  geom_point() +
  stat_smooth(method = lm, se = FALSE) +
  geom_segment(aes(xend = big5_agr, yend = .fitted), color = "red", size = 0.3)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'

6.3 Check linearity with Residuals vs Fitted plot

The below plot shows some minor non-linearity to our data. The red line is still very close to out zero line and would be considered a “good” graph of residuals vs fitted.

plot(reg_model, 1)

6.4 Check for outliers

The Cook’s distance plot (seen below) shows that none of our outliers would have an overwhelming effect on the regression. The point of significance in Cook’s distance is .5 and none of our points even extend past .03. Overall our variance is very small.

As for our Residuals vs Leverage graph below, we can see a nearly linear relationship. This indicates that no points are exerting leverage in a way that would skew our results.

# Cook's distance
plot(reg_model, 4)

# Residuals vs Leverage
plot(reg_model, 5)

6.5 Issues with My Data

As shown in the graphs above the data being used meets the requirements for each of our tests. The Cook’s distance graphs and the residuals vs leverage graph both show signs that our data is correlated with few to no outliers negatively effecting the relationship between out two variables.

7 View Test Output

Trivial: Less than 0.10 Small: 0.10–0.29 Medium: 0.30–0.49 Large: 0.50 or greater

summary(reg_model)
## 
## Call:
## lm(formula = pas_covid ~ big5_agr, data = d)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.2344 -0.4479  0.0139  0.4366  1.8004 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.17355    0.09842   32.24   <2e-16 ***
## big5_agr     0.01304    0.01918    0.68    0.497    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6839 on 1007 degrees of freedom
## Multiple R-squared:  0.0004589,  Adjusted R-squared:  -0.0005337 
## F-statistic: 0.4623 on 1 and 1007 DF,  p-value: 0.4967
# note for section below: to type lowercase Beta below (ß) you need to hold down Alt key and type 225 on numeric keypad. If that doesn't work you should be able to copy/paste it from somewhere else

8 Write Up Results

To test our hypothesis that Agreeableness (measured by the BFI) will significantly predict Pandemic related Anxiety (measured by the PAS), and that the relationship will be negative, we used a simple linear regression to model the relationship between the variables. We confirmed that our data met the assumptions of a linear regression, checking the linearity of the relationship using a Residuals vs Fitted plot and checking for outliers using Cook’s distance and a Residuals vs Leverage plot.

Counter to our prediction, we found that Agreeableness did not significantly predict Pandemic related Anxiety, Adj. R2 = .0005, F(1,1007) = .46, p < .5. The relationship between Agreeableness and Pandemic related Anxiety was slightly positive, ß = .01, t(1007) = .68, p = .50 (refer to Figure 1). According to Cohen (1988), this constitutes a large effect size (> .50).

References

Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.