1 Loading Libraries

#install.packages("sjPlot")

library(psych) # for the describe() command
library(car) # for the vif() command
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
library(sjPlot) # to visualize our results
## Install package "strengejacke" from GitHub (`devtools::install_github("strengejacke/strengejacke")`) to load all sj-packages at once!

2 Importing Data

# For HW, import the dataset you cleaned previously, this will be the dataset you'll use throughout the rest of the semester

d <- read.csv(file="Data/projectdata.csv", header =T)

3 State Your Hypothesis

We hypothesize that extroversion, brief resilience scale, and the mental flexibility questionnaire (state) will significantly effect the pandemic anxiety scale.

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':    316 obs. of  7 variables:
##  $ X        : int  6291 6294 6312 6326 6331 6335 6348 6350 6357 6359 ...
##  $ mhealth  : chr  "none or NA" "depression" "anxiety disorder" "none or NA" ...
##  $ age      : chr  "1 under 18" "1 under 18" "1 under 18" "2 between 18 and 25" ...
##  $ big5_ext : num  3 5.67 3.33 2.67 2.33 ...
##  $ pas_covid: num  2.33 3.11 3.78 2.56 3.89 ...
##  $ mfq_state: num  4 4 3.12 3.12 3.88 ...
##  $ brs      : num  4 2.5 2.33 2 2.83 ...
# Place only variables of interest in new dataframe
cont <- na.omit(subset(d, select = c(big5_ext, brs, mfq_state, pas_covid)))

# Standardize all IVs
cont$big5_ext <- scale(cont$big5_ext, center=T, scale=T)
cont$brs <- scale(cont$brs, center=T, scale=T)
cont$mfq_state <- scale(cont$mfq_state, center=T, scale=T)
cont$pas_covid <- scale(cont$pas_covid, center=T, scale=T)

# you can use the describe() command on an entire dataframe (d) or just on a single variable
describe(cont)
##           vars   n mean sd median trimmed  mad   min  max range  skew kurtosis
## big5_ext     1 316    0  1   0.04   -0.01 1.03 -2.05 2.13  4.18  0.00    -0.77
## brs          2 316    0  1  -0.04    0.00 1.13 -1.95 2.64  4.59  0.10    -0.66
## mfq_state    3 316    0  1   0.14    0.03 1.12 -2.63 2.27  4.90 -0.27    -0.40
## pas_covid    4 316    0  1   0.15    0.02 1.01 -3.60 2.53  6.12 -0.32     0.58
##             se
## big5_ext  0.06
## brs       0.06
## mfq_state 0.06
## pas_covid 0.06
# also use histograms to examine your continuous variables
hist(cont$big5_ext)

hist(cont$brs)

hist(cont$mfq_state)

hist(cont$pas_covid)

# last, use scatterplots to examine your continuous variables together
plot(cont$big5_ext, cont$pas_covid)       # PUT YOUR DV 2ND (Y-AXIS)

plot(cont$brs, cont$pas_covid)       # PUT YOUR DV 2ND (Y-AXIS)

plot(cont$mfq_state, cont$pas_covid)       # PUT YOUR DV 2ND (Y-AXIS)

plot(cont$big5_ext, cont$brs)

plot(cont$big5_ext, cont$mfq_state)

plot(cont$brs, cont$mfq_state)

5 View Your Correlations

corr_output_m <- corr.test(cont)
corr_output_m
## Call:corr.test(x = cont)
## Correlation matrix 
##           big5_ext   brs mfq_state pas_covid
## big5_ext      1.00  0.36      0.31     -0.09
## brs           0.36  1.00      0.68     -0.32
## mfq_state     0.31  0.68      1.00     -0.18
## pas_covid    -0.09 -0.32     -0.18      1.00
## Sample Size 
## [1] 316
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           big5_ext brs mfq_state pas_covid
## big5_ext      0.00   0         0      0.11
## brs           0.00   0         0      0.00
## mfq_state     0.00   0         0      0.00
## pas_covid     0.11   0         0      0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
# CHECK FOR CORRELATIONS AMONG IVs ABOVE .70 --> BAD (aka multicollinearity)

The results show that there was no multicollinearity within any of my tested categories.

6 Run a Multiple Linear Regression

# use the lm() command to run the regression
# DV on the left,  IVs on the right separated by "+"
reg_model <- lm(pas_covid ~ big5_ext + brs + mfq_state, data = cont)

7 Check Your Assumptions

7.1 Multiple Linear Regression Assumptions

Assumptions we’ve discussed previously:

  • Observations should be independent
  • Variables should be continuous and normally distributed
  • Outliers should be identified and removed (for our class, we will not be removing outliers, just identifying them)
  • Relationship between the variables should be linear

New assumptions:

  • Number of cases should be adequate (N ≥ 80 + 8*m, where m is the number of IVs)
  • Independent variables should not be too correlated (aka multicollinearity)
  • Residuals should be normal and have constant variance

7.2 Count Number of Cases

needed <- 80 + 8*3
nrow(cont) >= needed
## [1] TRUE

NOTE: For your homework, if you don’t have the required number of cases you’ll need to drop one of your independent variables. Reach out to me and we can figure out the best way to proceed!

7.3 Check for multicollinearity

  • Higher values indicate more multicollinearity
  • Cutoff is usually 5
# Variance Inflation Factor = VIF
vif(reg_model)
##  big5_ext       brs mfq_state 
##  1.156359  1.957424  1.886847

NOTE: For your homework, you will need to discuss multicollinearity and any high values, but you don’t have to drop any variables.

7.4 Check linearity with Residuals vs Fitted plot

The plot below shows the residuals for each case and the fitted line. The red line is the average residual for the specified point of the dependent variable. If the assumption of linearity is met, the red line should be horizontal. This indicates that the residuals average to around zero. However, a bit of deviation is okay – just like with skewness and kurtosis, there’s a range that we can work in before non-normality becomes a critical issue. For some examples of good Residuals vs Fitted plot and ones that show serious errors, check out this page.

plot(reg_model, 1)

NOTE: For your homework, you’ll simply need to generate this plot and talk about whether your assumptions are met. This is going to be a judgement call, and that’s okay! In practice, you’ll always be making these judgement calls as part of a team, so this assignment is just about getting experience with it, not making the perfect call.

The results depict a graph that meets the required assumptions. Based on the good plot from the website, my Residuals versus Linearity plot appears to represent the data in a “good” manner.

7.5 Check for outliers using Cook’s distance and a Residuals vs Leverage plot

The plots below both address leverage, or how much each data point is able to influence the regression line. Outliers are points that have undue influence on the regression line, the way that Bill Gates entering the room has an undue influence on the mean income.

The first plot, Cook’s distance, is a visualization of a score called (you guessed it) Cook’s distance, calculated for each case (aka row or participant) in the dataframe. Cook’s distance tells us how much the regression would change if the point was removed. The second plot also includes the residuals in the examination of leverage. The standardized residuals are on the y-axis and leverage is on the x-axis; this shows us which points have high residuals (are far from the regression line) and high leverage. Points that have large residuals and high leverage are especially worrisome, because they are far from the regression line but are also exerting a large influence on it.

# Cook's distance
plot(reg_model, 4)

# Residuals vs Leverage
plot(reg_model, 5)

NOTE: For your homework, you’ll simply need to generate these plots, assess Cook’s distance in your dataset, and then identify any potential cases that are prominent outliers. Since we have some cutoffs, that makes this process is a bit less subjective than some of the other assessments we’ve done here, which is nice change!

When running the Cook’s distance in the data set, there are no prominent outliers as all of the listed data points lie below the threshold.

7.6 Check homogeneity of variance in a Scale-Location plot

This plot shows us the standardized residuals across the range of the regression line. Because the residuals are standardized, large residuals (whether positive or negative) are at the top of the plot, while small residuals (whether positive or negative) are at the bottom of the plot. If the assumption of homogeneity of variance (also called homoscedasticity) is met, the red line should be mostly flat, horizontal. If it deviates from the mean line, that means that the variance is smaller or larger at that point of the regression line.

You can check out this page for some other examples of this type of plot.

plot(reg_model, 3)

### LAB ONLY - DELETE CODE BELOW FOR HW
## We can use the residual plot below to see the variance issues with our ‘fake’ variable.

NOTE: For your homework, you’ll simply need to generate the Scale-Location plot and talk about how your plot compares to the ones pictured in the link above. Is it closer to the ‘good’ plots or one of the ‘bad’ plots? Again, this is a judgement call! It’s okay if feel uncertain, and you won’t be penalized for that.

In the Scale-Location plot, the plot aligns more with the “good plots” than the “bad plots”.

7.7 Check normality of residuals with a Q-Q plot

This plot is a bit new. It’s called a Q-Q plot and shows the standardized residuals plotted against a normal distribution. If our variables are perfectly normal, the points will fit on the dashed line perfectly. This page shows how different types of non-normality appear on a Q-Q plot.

It’s normal for Q-Q plots show a bit of deviation at the ends. This page shows some examples that help us put our Q-Q plot into context.

plot(reg_model, 2)

NOTE: For your homework, you’ll simply need to generate this plot and talk about how your plot compares to the ones pictured. Does it seem like any skew or kurtosis (i.e., thin/thick tails) is indicated by your plot ? Is it closer to the ‘good’ or ‘bad’ plots from the second link above?

Compared to other plots, this Q-Q plot is one of the bad ones. There is a thin tail indicating skew and kurtosis. The plot is also showing a skew to the right. ## Issues with My Data

Before interpreting our results, we assessed our variables to see if they met the assumptions for a multiple linear regression. We analyzed a Scale-Location plot and detected slight issues with homogeneity of variance, as well as slight issues with linearity in a Residuals vs Fitted plot. However, we did not detect any outliers (visually analyzing Cook’s Distance and Residuals vs Leverage plots) or any serious issues with the normality of our residuals (visually analyzing a Q-Q plot), nor were there any issues of multicollinearity among our three independent variables.

8 View Test Output

summary(reg_model)
## 
## Call:
## lm(formula = pas_covid ~ big5_ext + brs + mfq_state, data = cont)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2416 -0.6182  0.0265  0.6984  2.5211 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.259e-15  5.356e-02   0.000    1.000    
## big5_ext     1.997e-02  5.769e-02   0.346    0.729    
## brs         -3.651e-01  7.506e-02  -4.865 1.82e-06 ***
## mfq_state    6.253e-02  7.369e-02   0.849    0.397    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9521 on 312 degrees of freedom
## Multiple R-squared:  0.102,  Adjusted R-squared:  0.09341 
## F-statistic: 11.82 on 3 and 312 DF,  p-value: 2.364e-07
# you do not have to run the below code for the HW
#reg_model_test <- lm(rel_stability ~ satis, data = cont)
#summary(reg_model_test)

# 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

Effect size, based on Regression Beta (Estimate) value Trivial: Less than 0.10 Small: 0.10–0.29 Medium: 0.30–0.49 Large: 0.50 or greater

9 Write Up Results

To test our hypothesis extroversion, brief resilience scale, and the mental flexibility questionnaire (state) would significantly predict anxiety on the pandemic anxiety scale, we used a multiple linear regression to model the associations between these variables. We confirmed that our data met the assumptions of a linear regression, and although there were slight issues with homogeneity of variance and linearity we still continued on with the analysis. The results depict a graph that meets the required assumptions. Based on the good plot from the website, my Residuals versus Linearity plot appears to represent the data in a “good” manner. When running the Cook’s distance in the data set, there are no prominent outliers as all of the listed data points lie below the threshold. In the Scale-Location plot, the plot aligns more with the “good plots” than the “bad plots”. Compared to other plots, this Q-Q plot is one of the bad ones. There is a thin tail indicating skew and kurtosis. The plot is also showing a skew to the right.

Our model was not statistically significant, Adj. R2 = .09 , F(3,312) = 11.82, <.001 . The relationship between extroversion, brief resilience scale, and Mental Flexibility Questionnaire (State) was negative and has a medium effect size for brief resilience scale, small effect size for Mental Flexibility Questionnaire (State), and a trivial effect size for extroversion (per Cohen, 1988). The only significant relationship was between the Brief Resilience Scale and the Pandemic Anxiety Scale. Full output from the regression model is reported in Table 1.

Table 1: Multiple Regression Model Predicting Relationship Stabilty
  Pandemic Anxiety Scale
Predictors Estimates SE CI p
Intercept 0.00 0.05 -0.11 – 0.11 1.000
Extroversion 0.02 0.06 -0.09 – 0.13 0.729
Brief Resilience Scale -0.37 0.08 -0.51 – -0.22 <0.001
Mental Flexibility Questionnaire (State) 0.06 0.07 -0.08 – 0.21 0.397
Observations 316
R2 / R2 adjusted 0.102 / 0.093


 

References

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