1 Loading Libraries

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(remotes)
# install_version("estimability", version = "1.4.1")
library(sjPlot) # to visualize our results

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/eammi2fakedata_final.csv", header=T)

set.seed(110)
# do not run this code for the homework

3 State Your Hypothesis

I hypothesize that Narcissism (measured by the NPI), Percieved Stress (measured by the PSQ), and interpersonal exploitativeness (measured by the IES) will significantly predict subjective well-being (measured by the SWLS).

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':    3155 obs. of  7 variables:
##  $ ResponseId: chr  "R_BJN3bQqi1zUMid3" "R_2TGbiBXmAtxywsD" "R_12G7bIqN2wB2N65" "R_39pldNoon8CePfP" ...
##  $ gender    : chr  "f" "m" "m" "f" ...
##  $ race_rc   : chr  "white" "white" "white" "other" ...
##  $ swb       : num  4.33 4.17 1.83 5.17 3.67 ...
##  $ npi       : num  0.6923 0.1538 0.0769 0.0769 0.7692 ...
##  $ exploit   : num  2 3.67 4.33 1.67 4 ...
##  $ stress    : num  3.3 3.3 4 3.2 3.1 3.5 3.3 2.4 2.9 2.7 ...
cont <- na.omit(subset(d, select=c(swb, npi, exploit, stress)))
cont$swb <- scale(cont$swb, center=T, scale=T)
cont$npi <- scale(cont$npi, center=T, scale=T)
cont$exploit <- scale(cont$exploit, center=T, scale=T)
cont$stress <- scale(cont$stress, 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
## swb        1 3155    0  1   0.14    0.04 1.12 -2.63 1.91  4.54 -0.36    -0.46
## npi        2 3155    0  1  -0.41   -0.13 0.74 -0.91 2.34  3.25  0.94    -0.69
## exploit    3 3155    0  1  -0.28   -0.13 1.08 -1.01 3.36  4.37  0.95     0.36
## stress     4 3155    0  1  -0.09   -0.01 0.99 -2.92 2.75  5.67  0.03    -0.17
##           se
## swb     0.02
## npi     0.02
## exploit 0.02
## stress  0.02
# also use histograms to examine your continuous variables
hist(cont$swb)

hist(cont$npi)

hist(cont$exploit)

hist(cont$stress)

# last, use scatterplots to examine your continuous variables together
plot(cont$swb, cont$npi)

plot(cont$npi, cont$exploit)

plot(cont$npi, cont$stress)

plot(cont$swb, cont$exploit)

plot(cont$swb, cont$stress)

plot(cont$exploit, cont$stress)

5 View Your Correlations

corr_output_m <- corr.test(cont)
corr_output_m
## Call:corr.test(x = cont)
## Correlation matrix 
##           swb   npi exploit stress
## swb      1.00  0.03   -0.08  -0.50
## npi      0.03  1.00    0.36  -0.06
## exploit -0.08  0.36    1.00   0.03
## stress  -0.50 -0.06    0.03   1.00
## Sample Size 
## [1] 3155
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##          swb  npi exploit stress
## swb     0.00 0.12    0.00   0.00
## npi     0.06 0.00    0.00   0.00
## exploit 0.00 0.00    0.00   0.12
## stress  0.00 0.00    0.06   0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

6 Run a Multiple Linear Regression

# use the lm() command to run the regression
# dependent/outcome variable on the left, independent/predictor variables on the right
reg_model <- lm(swb ~ npi + exploit + stress, data = cont)
# DV ~ IV1, IV2, IV3

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 + 8m, 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

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!

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

7.3 Check multicollinearity

  • Higher values indicate more multicollinearity
  • Cutoff is usually 5

For your homework, you will need to discuss multicollinearity and any high values, but you don’t have to drop any variables. # just need to say either that there is not high multicollinearity if it is below 5, or high if it is above 5

vif(reg_model)
##      npi  exploit   stress 
## 1.156024 1.153031 1.007310
# Cutoff values below 5, not high multicollinearity.

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.

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. #$ if red line is above/below 1/-1 might not have great linearity

plot(reg_model, 1)

# Has good linearity, red line is mostly straight and in between -1 and +1. 

7.5 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. 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 is indicated by your plot? Is it closer to the ‘good’/‘bad’ plots from the second link?

plot(reg_model, 2)

# if it is normal it is pretty diagnally , it is okay for some deviation at the ends. 
# It is normal, ansd has normnality. 

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

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 a nice change!

# Cook's distance
plot(reg_model, 4)

# Residuals vs Leverage
plot(reg_model, 5)

# if the points were far to the right, or if the red line is getting dragged down or up then there may be outliers. 
# There a few slight outliers, but nothing too strong. 

7.7 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 standarized, 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 horizontal. If it deviates from the mean line, that means that the variance is smaller or larger at that point of the regression line.

Once again, you can check out this page for some other examples of this type of plot. For your homework, you’ll simply need to generate this plot and talk about how your plot compares to the ones pictured. 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.

plot(reg_model, 3)

# want the red line to be as straight as possible, if it isn't there may be some issues. 
# There may be some issues with homogeneity if variance, since the red line is going down?? 

7.8 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 some issues with homogeneity of variance, as well as some issues with linearity in a Residuals vs Fitted plot. However, we did not detect any outliers (visually analyzing a Residuals vs Leverage plot) or any serious issues with the normality of our residuals (visually analyzing a Q-Q plot).

8 View Test Output

summary(reg_model)
## 
## Call:
## lm(formula = swb ~ npi + exploit + stress, data = cont)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -3.12788 -0.60954  0.05169  0.62707  2.69917 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  5.162e-17  1.535e-02   0.000   1.0000    
## npi          2.896e-02  1.651e-02   1.754   0.0795 .  
## exploit     -7.218e-02  1.649e-02  -4.377 1.24e-05 ***
## stress      -4.983e-01  1.541e-02 -32.329  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8624 on 3151 degrees of freedom
## Multiple R-squared:  0.257,  Adjusted R-squared:  0.2563 
## F-statistic: 363.2 on 3 and 3151 DF,  p-value: < 2.2e-16
plot_model(reg_model, type="std")

plot_model(reg_model, type="emm", terms = c("npi"))

plot_model(reg_model, type="emm", terms = c("exploit"))

plot_model(reg_model, type="emm", terms = c("stress"))

# use the three IV's
# stronger slant shows a stronger relationship, if it goes down its a negative relationship and if it goes up it is positive relationship
# There is a strong negative relationship between swb and stress. There is a average strength positive relationship between swb and npi. There is a strong negative relationship between exploit and swb. 

# 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

9 Write Up Results

To test our hypothesis that narcissism (measured by the NPI), interpersonal exploitativeness (measured by the IES), and stress (measured by the PSQ) would significantly predict subjective well-being (measured by the SWLS), we used a multiple linear regression to model the relationship between the variables. We confirmed that our data met the assumptions of a linear regression, and although there were some issues with outliers and homogeneity of variance and linearity we continued with the analysis anyway.

Our model was statistically significant, Adj. R2 = .26, F(3,3151) = 363.2, p < .001. The relationship between npi and subjective wellbeing was positive and has a small effect size (per Cohen, 1988), while the relationships between our remaining predictors (exploitativeness and stress) and our outcome (subjective wellbeing) were negative and had effect sizes that were small. Full output from the regression model is reported in Table 1. # if its not statisticslly significant, do not talk about the effect size, look at the effecient? maybe?
Table 1: Regression model of subjective wellbeing
  Subjective Wellbeing (SWLS)
Predictors Estimates SE CI p
Intercept 0.00 0.02 -0.03 – 0.03 1.000
Narcissism (NPI) 0.03 0.02 -0.00 – 0.06 0.080
Interpersonal Exploitativeness (IES) -0.07 0.02 -0.10 – -0.04 <0.001
Stress (PSQ) -0.50 0.02 -0.53 – -0.47 <0.001
Observations 3155
R2 / R2 adjusted 0.257 / 0.256


 

References

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