#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!
# 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)
We hypothesize that the scores for the GAD-7 survey on levels of anxiety and the PHQ-9 survey measuring levels of depression will significantly predict the responses to the PSS-4 survey where participants report levels of stress they are experiencing.
# 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': 1258 obs. of 7 variables:
## $ X : int 1 321 401 469 520 1390 1422 1849 2183 2247 ...
## $ gender : chr "female" "male" "female" "female" ...
## $ mhealth: chr "none or NA" "none or NA" "obsessive compulsive disorder" "depression" ...
## $ rse : num 2.3 3.8 3.1 3 2.6 3 1.3 2.1 3 3.2 ...
## $ pss : num 3.25 2.25 2.25 2.25 2.75 2.75 4.75 3.25 3.5 2.25 ...
## $ phq : num 1.33 1.89 2.44 1.22 1.56 ...
## $ gad : num 1.86 1 2.14 1.71 1.14 ...
# Place only continuous variables of interest in new dataframe, and name it "cont"
cont <- na.omit(subset(d, select=c(gad, phq, pss)))
cont$row_id <- 1:nrow(cont)
# Standardize all IVs
cont$gad <- scale(cont$gad, center=T, scale=T)
cont$phq <- scale(cont$phq, 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
## gad 1 1258 0.00 1.00 -0.36 -0.10 0.93 -1.14 2.16 3.30 0.68
## phq 2 1258 0.00 1.00 -0.21 -0.09 1.14 -1.24 2.23 3.47 0.64
## pss 3 1258 2.93 0.95 3.00 2.92 1.11 1.00 5.00 4.00 0.10
## row_id 4 1258 629.50 363.30 629.50 629.50 466.28 1.00 1258.00 1257.00 0.00
## kurtosis se
## gad -0.72 0.03
## phq -0.69 0.03
## pss -0.74 0.03
## row_id -1.20 10.24
# also use histograms to examine your continuous variables (all IVs and DV)
hist(cont$gad)
hist(cont$phq)
hist(cont$pss)
# last, use scatterplots to examine each pairing of your continuous variables together
plot(cont$gad, cont$pss) # PUT YOUR DV 2ND (Y-AXIS)
plot(cont$phq, cont$pss) # PUT YOUR DV 2ND (Y-AXIS)
plot(cont$gad, cont$phq) # Check relationship between IVs, order does not matter
corr_output_m <- corr.test(cont)
corr_output_m
## Call:corr.test(x = cont)
## Correlation matrix
## gad phq pss row_id
## gad 1.00 0.84 0.76 0.08
## phq 0.84 1.00 0.75 0.04
## pss 0.76 0.75 1.00 0.00
## row_id 0.08 0.04 0.00 1.00
## Sample Size
## [1] 1258
## Probability values (Entries above the diagonal are adjusted for multiple tests.)
## gad phq pss row_id
## gad 0 0.00 0.00 0.01
## phq 0 0.00 0.00 0.35
## pss 0 0.00 0.00 0.93
## row_id 0 0.18 0.93 0.00
##
## To see confidence intervals of the correlations, print with the short=FALSE option
# CHECK FOR ANY CORRELATIONS AMONG YOUR IVs ABOVE .70 --> BAD (aka multicollinearity)
# ONLY use the commented out section below IF if you need to remove outliers AFTER examining the Cook's distance and a Residuals vs Leverage plots in your HW -- remember we practiced this in the ANOVA lab
#cont <- subset(cont, row_id!=c(1970) & row_id!=c(250))
# use the lm() command to run the regression. Put DV on the left, IVs on the right separated by "+"
reg_model <- lm(pss ~ gad + phq, data = cont)
Assumptions we’ve discussed previously:
New assumptions:
needed <- 80 + 8*2
nrow(cont) >= needed
## [1] TRUE
NOTE: For your homework, if you don’t have the required number of cases reach out to me and we can figure out the best way to proceed!
# Variance Inflation Factor = VIF
vif(reg_model)
## gad phq
## 3.372684 3.372684
NOTE: For your homework, you will need to discuss multicollinearity and any high values in “Issues with My Data”, but you don’t have to drop any variables.
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)
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 and remove any potential cases that are prominent outliers (like we did in the ANOVA lab). You will make a note of this in the “Issues with My Data” write-up.
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 think about how your plot compares to the normal/non-normal plots pictured in the links above. Does it seem like the points lie mostly along the straight diagonal line with either no or some minor deviations along each of the tails? If so, your residuals are likely normal enough to meet the assumption. You will talk about this in the write-up below.
Before interpreting our results, we assessed our variables to see if they met the assumptions for a multiple linear regression. We detected slight issues with linearity in a Residuals vs Fitted plot. We did not detect any outliers (by visually analyzing Cook’s Distance and Residuals vs Leverage plots) or any serious issues with the normality of our residuals (by visually analyzing a Q-Q plot), however there were some issues of multicollinearity among our two independent variables, as they were both correlated above 0.7.
summary(reg_model)
##
## Call:
## lm(formula = pss ~ gad + phq, data = cont)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.64192 -0.39895 -0.00126 0.40696 2.01613
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.93045 0.01646 178.07 <2e-16 ***
## gad 0.41314 0.03023 13.66 <2e-16 ***
## phq 0.36806 0.03023 12.17 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5837 on 1255 degrees of freedom
## Multiple R-squared: 0.6226, Adjusted R-squared: 0.622
## F-statistic: 1035 on 2 and 1255 DF, p-value: < 2.2e-16
# 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 in our output
To test our hypothesis that partner attractiveness and relationship satisfaction would significantly predict relationship stability, we used a regression to model the associations between these variables. We confirmed that our data met the assumptions of a linear regression, aside from there being slight issues with linearity and a significant sign of multicollinearity.
Our hypothesis was supported. The model was statistically significant, Adj. R2 = .62, F(2 1255) = 1035.00, p < .001. Our results indicate that relationship satisfaction positively predicts relationship stability and had a medium effect size (0.30 < ß > 0.49; per Cohen, 1988), while partner attractiveness also positively predicts relationship stability and had a medium effect size (0.30 < ß < 0.49). Full output from the regression model is reported in Table 1. This means that people’s pss scores increase by 0.37 units for every one unit increase in their phq scores, and it increases by 0.41 units for every one unit increase in their gad scores.
PSS Scores | ||||
---|---|---|---|---|
Predictors | Estimates | SE | CI | p |
Intercept | 2.93 | 0.02 | 2.90 – 2.96 | <0.001 |
GAD Scores for Anxiety | 0.41 | 0.03 | 0.35 – 0.47 | <0.001 |
PHQ Scores for Depression | 0.37 | 0.03 | 0.31 – 0.43 | <0.001 |
Observations | 1258 | |||
R2 / R2 adjusted | 0.623 / 0.622 |
References
Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.