#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
# 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 self efficacy and perceived social support will significantly predict traits of narcissism. The relationship between self efficacy and narcissism will be negative, and the relationship between perceived social support and narcissism will also be negative.
# 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': 3156 obs. of 7 variables:
## $ ResponseID: chr "R_BJN3bQqi1zUMid3" "R_2TGbiBXmAtxywsD" "R_12G7bIqN2wB2N65" "R_39pldNoon8CePfP" ...
## $ sibling : chr "at least one sibling" "at least one sibling" "at least one sibling" "at least one sibling" ...
## $ race_rc : chr "white" "white" "white" "other" ...
## $ belong : num 2.8 4.2 3.6 4 3.4 4.2 3.9 3.6 2.9 2.5 ...
## $ support : num 6 6.75 5.17 5.58 6 ...
## $ npi : num 0.6923 0.1538 0.0769 0.0769 0.7692 ...
## $ efficacy : num 3.4 3.4 2.2 2.8 3 2.4 2.3 3 3 3.7 ...
# Place only continuous variables of interest in new dataframe, and name it "cont"
cont <- na.omit(subset(d, select=c(support, npi, efficacy)))
cont$row_id <- 1:nrow(cont)
# Standardize all IVs
cont$support <- scale(cont$support, center=T, scale=T)
cont$efficacy <- scale(cont$efficacy, 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
## support 1 3156 0.00 1.00 0.19 0.11 0.87 -4.90 1.30 6.20
## npi 2 3156 0.28 0.31 0.15 0.24 0.23 0.00 1.00 1.00
## efficacy 3 3156 0.00 1.00 -0.06 0.01 1.00 -4.54 1.96 6.49
## row_id 4 3156 1578.50 911.20 1578.50 1578.50 1169.77 1.00 3156.00 3155.00
## skew kurtosis se
## support -1.10 1.43 0.02
## npi 0.94 -0.69 0.01
## efficacy -0.24 0.44 0.02
## row_id 0.00 -1.20 16.22
# also use histograms to examine your continuous variables (all IVs and DV)
hist(cont$support)
hist(cont$efficacy)
hist(cont$npi)
# last, use scatterplots to examine each pairing of your continuous variables together
plot(cont$support, cont$npi) # PUT YOUR DV 2ND (Y-AXIS)
plot(cont$efficacy, cont$npi) # PUT YOUR DV 2ND (Y-AXIS)
plot(cont$support, cont$efficacy) # Check relationship between IVs, order does not matter
corr_output_m <- corr.test(cont)
corr_output_m
## Call:corr.test(x = cont)
## Correlation matrix
## support npi efficacy row_id
## support 1.00 -0.02 0.21 0.02
## npi -0.02 1.00 0.17 0.00
## efficacy 0.21 0.17 1.00 -0.02
## row_id 0.02 0.00 -0.02 1.00
## Sample Size
## [1] 3156
## Probability values (Entries above the diagonal are adjusted for multiple tests.)
## support npi efficacy row_id
## support 0.00 0.93 0.00 0.93
## npi 0.25 0.00 0.00 0.93
## efficacy 0.00 0.00 0.00 0.93
## row_id 0.23 0.84 0.31 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))
# use the lm() command to run the regression. Put DV on the left, IVs on the right separated by "+"
reg_model <- lm(npi ~ support + efficacy, data = cont )
Assumptions we’ve discussed previously:
New assumptions:
needed <- 80 + 8*2
nrow(cont) >= needed
## [1] TRUE
# Variance Inflation Factor = VIF
vif(reg_model)
## support efficacy
## 1.044882 1.044882
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)
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)
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). The Q-Q plot showed a thick tail representation of the data, but there were no issues of multicollinearity among our two independent variables.
summary(reg_model)
##
## Call:
## lm(formula = npi ~ support + efficacy, data = cont)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.4298 -0.2229 -0.1330 0.3221 0.8111
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.279126 0.005394 51.75 < 2e-16 ***
## support -0.017756 0.005514 -3.22 0.00129 **
## efficacy 0.055358 0.005514 10.04 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.303 on 3153 degrees of freedom
## Multiple R-squared: 0.03138, Adjusted R-squared: 0.03076
## F-statistic: 51.07 on 2 and 3153 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 perceived social support and self efficacy would significantly predict narcissistic personality traits, 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 partially supported. The model was statistically significant, F(51.07) = (2, 3153), p < 0.001, Adj. R2 = 0.03. Our results indicate that social support negatively predicted narcissistic traits and had a trivial effect size (ß < 0.10; per Cohen, 1988), however, contrary to prediction, self efficacy positively predicted narcissistic traits and had a trivial effect size (ß < 0.10). Full output from the regression model is reported in Table 1. This means that people’s relationship stability decreases by 0.02 units for every one unit increase in their perceived social support, while it increases by 0.06 units for every one unit increase in self efficacy.
| Narcissistic Traits | ||||
|---|---|---|---|---|
| Predictors | Estimates | SE | CI | p |
| Intercept | 0.28 | 0.01 | 0.27 – 0.29 | <0.001 |
| Perceived Social Support | -0.02 | 0.01 | -0.03 – -0.01 | 0.001 |
| Self Efficacy | 0.06 | 0.01 | 0.04 – 0.07 | <0.001 |
| Observations | 3156 | |||
| R2 / R2 adjusted | 0.031 / 0.031 | |||
References
Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.