#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
## Warning: package 'sjPlot' was built under R version 4.6.2
d <- read.csv(file="Data/projectdata.csv", header=T)
I hypothesize that intolerance of uncertainty and perceived stress will significantly predict generalized anxiety. The relationship between intolerance of uncertainty and generalized anxiety will be positive, and the relationship between perceived stress and generalized anxiety will also be positive. # 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': 685 obs. of 7 variables:
## $ X : int 520 2814 3146 3295 717 6056 4753 2044 1965 1246 ...
## $ education: chr "1 equivalent to not completing high school" "prefer not to say" "2 equivalent to high school completion" "prefer not to say" ...
## $ mhealth : chr "none or NA" "none or NA" "none or NA" "none or NA" ...
## $ iou : num 2.22 1.52 1.78 1.85 2.22 ...
## $ mfq_26 : num 2.7 4.55 4.8 3.8 4.5 4 5.8 4.5 5.25 5.15 ...
## $ pss : num 2.75 2.25 3 2 1.75 2 1 3 1.25 1.25 ...
## $ gad : num 1.14 1.29 1 1 1.14 ...
# Place only continuous variables of interest in new dataframe, and name it "cont"
cont <- na.omit(subset(d, select=c(gad,iou,pss)))
cont$row_id <- 1:nrow(cont)
# Standardize all IVs
cont$iou <- scale(cont$iou, center=T, scale=T)
cont$pss <- scale(cont$pss, center=T, scale=T)
# 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
## X 1 685 5200.06 2585.40 5845.00 5349.83 2959.27 20.0 8860.00
## education* 2 685 2.19 1.48 2.00 1.91 1.48 1.0 6.00
## mhealth* 3 685 4.58 1.43 5.00 4.83 0.00 1.0 8.00
## iou 4 685 2.69 0.92 2.56 2.65 1.04 1.0 4.89
## mfq_26 5 685 4.24 0.65 4.25 4.25 0.67 1.8 6.00
## pss 6 685 3.14 0.94 3.25 3.15 1.11 1.0 5.00
## gad 7 685 2.19 0.92 2.00 2.13 1.06 1.0 4.00
## range skew kurtosis se
## X 8840.00 -0.42 -1.11 98.78
## education* 5.00 1.40 0.97 0.06
## mhealth* 7.00 -1.50 2.25 0.05
## iou 3.89 0.30 -0.82 0.04
## mfq_26 4.20 -0.23 0.09 0.02
## pss 4.00 -0.13 -0.73 0.04
## gad 3.00 0.44 -1.01 0.04
# also use histograms to examine your continuous variables (all IVs and DV)
hist(cont$iou)
hist(cont$pss)
hist(cont$gad)
# last, use scatterplots to examine each pairing of your continuous variables together
plot(cont$iou, cont$gad) # PUT YOUR DV 2ND (Y-AXIS)
plot(cont$pss, cont$gad) # PUT YOUR DV 2ND (Y-AXIS)
plot(cont$iou, cont$pss) # 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 iou pss row_id
## gad 1.00 0.70 0.74 0.55
## iou 0.70 1.00 0.62 0.49
## pss 0.74 0.62 1.00 0.57
## row_id 0.55 0.49 0.57 1.00
## Sample Size
## [1] 685
## Probability values (Entries above the diagonal are adjusted for multiple tests.)
## gad iou pss row_id
## gad 0 0 0 0
## iou 0 0 0 0
## pss 0 0 0 0
## row_id 0 0 0 0
##
## 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))
# use the lm() command to run the regression. Put DV on the left, IVs on the right separated by "+"
reg_model <- lm(gad ~ iou + pss , 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)
## iou pss
## 1.636972 1.636972
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, which = 1)
NOTE: For your homework, you’ll simply need to generate this plot and talk about whether the assumption was met in “Issues with My Data”. This is going to be a judgement call, and that’s okay!
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, which = 4)
# Residuals vs Leverage
plot(reg_model, which = 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 some slight curvature in a Residuals vs Fitted plot. We did not detect highly influential cases using the Cook’s distance cutoff of 0.50 (by visually analyzing Cook’s Distance and Residuals vs Leverage plots) or major problems with the normality of our residuals, although there were some tail deviations (by visually analyzing a Q-Q plot), nor were there any issues of multicollinearity among our two independent variables.
summary(reg_model)
##
## Call:
## lm(formula = gad ~ iou + pss, data = cont)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.60757 -0.37113 -0.02229 0.34110 2.56122
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.19416 0.02116 103.68 <2e-16 ***
## iou 0.35111 0.02710 12.96 <2e-16 ***
## pss 0.46690 0.02710 17.23 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5539 on 682 degrees of freedom
## Multiple R-squared: 0.6408, Adjusted R-squared: 0.6398
## F-statistic: 608.4 on 2 and 682 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 intolerance of uncertainty and percieved stress would significantly predict generalized-anxiety symptoms, 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, aside from there being slight issues with linearity.
Our hypothesis was supported . The model was significant, Adj. R2 = .64, F(2, 682) = 608.40, p < .001. Our results indicate that intolerance of uncertainty significantly and positively predicted generalized-anxiety symptoms and had a medium effect size (ß = .38; per Cohen, 1988), while perceived stress also significantly and positively predicted generalized-anxiety symptoms and had a large effect size (ß = .51). Full output from the regression model is reported in Table 1. This means that People’s predicted generalized-anxiety scores increased by .35 points for every one-standard-deviation increase in intolerance of uncertainty, holding perceived stress constant, while it increased by .47 points for every one-standard-deviation increase in perceived stress, holding intolerance of uncertainty constant.
| Generalized-Anxiety Symptoms | ||||
|---|---|---|---|---|
| Predictors | Estimates | SE | CI | p |
| Intercept | 2.19 | 0.02 | 2.15 – 2.24 | <0.001 |
| Intolerance of Uncertainty | 0.35 | 0.03 | 0.30 – 0.40 | <0.001 |
| Percieved Stress | 0.47 | 0.03 | 0.41 – 0.52 | <0.001 |
| Observations | 685 | |||
| R2 / R2 adjusted | 0.641 / 0.640 | |||
References
Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.