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

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 perceived social support and relationship mindful awareness will significantly predict perceived stress, and that the relationships will be negative. Specifically, those with higher perceived social support will report less perceived stress, and those with higher mindful awareness with also report less perceived stress.

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':    858 obs. of  7 variables:
##  $ ResponseID: chr  "R_12G7bIqN2wB2N65" "R_3lLnoV2mYVYHFvf" "R_1gTNDGWsqikPuEX" "R_3G1XvswZmPZTkMU" ...
##  $ race_rc   : chr  "white" "white" "white" "white" ...
##  $ disability: chr  "psychiatric" "other" "learning" "psychiatric" ...
##  $ support   : num  5.17 2.67 4.5 6.75 3.92 ...
##  $ mindful   : num  2.2 1.6 1.8 4.27 3.4 ...
##  $ belong    : num  3.6 2.4 3 3.5 3.3 2.7 3.8 2.6 3.8 4 ...
##  $ stress    : num  4 3.5 4.4 2.4 3.6 3 3 3.7 3.4 3.1 ...
# Place only continuous variables of interest in new dataframe, and name it "cont"
cont <- na.omit(subset(d, select=c(support, mindful, stress)))
cont$row_id <- 1:nrow(cont)

# Standardize all IVs
cont$support <- scale(cont$support, center=T, scale=T)
cont$mindful <- scale(cont$mindful, 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
## support    1 858   0.00   1.00   0.21    0.10   0.91 -4.34   1.37   5.71 -0.96
## mindful    2 858   0.00   1.00  -0.01    0.01   0.94 -2.79   2.61   5.40 -0.03
## stress     3 858   3.24   0.62   3.20    3.25   0.74  1.60   4.60   3.00 -0.08
## row_id     4 858 429.50 247.83 429.50  429.50 318.02  1.00 858.00 857.00  0.00
##         kurtosis   se
## support     0.76 0.03
## mindful    -0.19 0.03
## stress     -0.45 0.02
## row_id     -1.20 8.46
# also use histograms to examine your continuous variables (all IVs and DV)
hist(cont$stress)

hist(cont$support)

hist(cont$mindful)

# last, use scatterplots to examine each pairing of your continuous variables together
plot(cont$support, cont$stress)  # PUT YOUR DV 2ND (Y-AXIS)

plot(cont$mindful, cont$stress)  # PUT YOUR DV 2ND (Y-AXIS)

plot(cont$support, cont$mindful)  # Check relationship between IVs, order does not matter

5 View Your Correlations

corr_output_m <- corr.test(cont)
corr_output_m
## Call:corr.test(x = cont)
## Correlation matrix 
##         support mindful stress row_id
## support    1.00    0.19  -0.25   0.05
## mindful    0.19    1.00  -0.39   0.06
## stress    -0.25   -0.39   1.00   0.00
## row_id     0.05    0.06   0.00   1.00
## Sample Size 
## [1] 858
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##         support mindful stress row_id
## support    0.00    0.00   0.00   0.31
## mindful    0.00    0.00   0.00   0.19
## stress     0.00    0.00   0.00   0.93
## row_id     0.15    0.06   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)

6 Run a Multiple Linear Regression

# 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(  stress~support + mindful  , 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
  • Relationship between the variables should be linear
  • Homogeneity of variance [NOTE: We are skipping this here]
  • Residuals should be normal and have constant variance

New assumptions:

  • Number of cases should be adequate (N ≥ 80 + 8*m, where m is the number of independent variables)
  • Independent variables should not be too correlated (aka multicollinearity)

7.2 Count Number of Cases

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

7.3 Check for multicollinearity

  • Higher values indicate more multicollinearity
  • Cutoff is usually VIF > 5
# Variance Inflation Factor = VIF
vif(reg_model)
##  support  mindful 
## 1.037117 1.037117

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)

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)

7.6 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)

7.7 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 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), nor were there any issues of multicollinearity among our two independent variables.

8 View Test Output

summary(reg_model)
## 
## Call:
## lm(formula = stress ~ support + mindful, data = cont)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.69634 -0.36593  0.02113  0.37429  2.00809 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.24091    0.01920 168.809  < 2e-16 ***
## support     -0.11494    0.01956  -5.875 6.04e-09 ***
## mindful     -0.21831    0.01956 -11.159  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5624 on 855 degrees of freedom
## Multiple R-squared:  0.1823, Adjusted R-squared:  0.1804 
## F-statistic: 95.34 on 2 and 855 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

  • Trivial: Less than 0.10 (ß < 0.10)
  • Small: 0.10–0.29 (0.10 < ß < 0.29)
  • Medium: 0.30–0.49 (0.30 < ß < 0.49)
  • Large: 0.50 or greater (ß > 0.50)

9 Write Up Results

To test our hypothesis that perceived social support and mindful awareness would significantly predict perceived stress, and that the prediction would be negative we used a multiple 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 statistically significant, Adj. R2 = 0.18, F(2, 855) = 95.34, p < .001. Our results indicate that perceived social support negatively predicts perceived stress and had a small effect size (0.10 < ß < .29; per Cohen, 1988), while mindful awareness also negatively predicts perceived stress and had a small effect size (0.10 < ß < .29). Full output from the regression model is reported in Table 1. This means that people’s perceived stress decreased by 0.11 units for every one unit increase in their perceived social support, while it decreased by 0.22 units for every one unit increase in their mindful awareness.

Table 1: Multiple Regression Model Predicting Perceived Stress
  Perceived Stress
Predictors Estimates SE CI p
Intercept 3.24 0.02 3.20 – 3.28 <0.001
Perceived Social Support -0.11 0.02 -0.15 – -0.08 <0.001
Mindful Awareness -0.22 0.02 -0.26 – -0.18 <0.001
Observations 858
R2 / R2 adjusted 0.182 / 0.180


 

References

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