#install.packages("sjPlot")
library(psych) # for the describe() command
library(car) # for the vif() command
## Warning: package 'car' was built under R version 4.5.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.5.3
##
## 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.5.3
d <- read.csv(file="Data/projectdata.csv", header=T)
We hypothesize maturity and self-efficacy will significantly predict exploitativeness. The relationship between maturity and exploitativeness will be negative, and the relationship between self-efficacy and exploitativeness will be positive.
# 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': 3104 obs. of 7 variables:
## $ ResponseID : chr "R_BJN3bQqi1zUMid3" "R_2TGbiBXmAtxywsD" "R_12G7bIqN2wB2N65" "R_39pldNoon8CePfP" ...
## $ income : chr "1 low" "1 low" "rather not say" "rather not say" ...
## $ usdream : chr "american dream is important and achievable for me" "american dream is important and achievable for me" "american dream is not important and maybe not achievable for me" "american dream is not important and maybe not achievable for me" ...
## $ moa_maturity: num 3.67 3.33 3.67 3 3.67 ...
## $ mindful : num 2.4 1.8 2.2 2.2 3.2 ...
## $ efficacy : num 3.4 3.4 2.2 2.8 3 2.4 2.3 3 3 3.7 ...
## $ exploit : num 2 3.67 4.33 1.67 4 ...
# Place only continuous variables of interest in new dataframe, and name it "cont"
cont <- na.omit(subset(d, select=c(moa_maturity, efficacy, exploit )))
cont$row_id <- 1:nrow(cont)
# Standardize all IVs
cont$moa_maturity <- scale(cont$moa_maturity, 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
## moa_maturity 1 3104 0.00 1.00 0.17 0.14 1.15 -6.02 0.95
## efficacy 2 3104 0.00 1.00 -0.06 0.01 1.00 -4.55 1.96
## exploit 3 3104 2.39 1.37 2.00 2.21 1.48 1.00 7.00
## row_id 4 3104 1552.50 896.19 1552.50 1552.50 1150.50 1.00 3104.00
## range skew kurtosis se
## moa_maturity 6.97 -1.20 1.91 0.02
## efficacy 6.51 -0.24 0.44 0.02
## exploit 6.00 0.93 0.34 0.02
## row_id 3103.00 0.00 -1.20 16.09
# also use histograms to examine your continuous variables (all IVs and DV)
hist(cont$moa_maturity)
hist(cont$efficacy)
hist(cont$exploit)
# last, use scatterplots to examine each pairing of your continuous variables together
plot(cont$moa_maturity, cont$exploit) # PUT YOUR DV 2ND (Y-AXIS)
plot(cont$efficacy, cont$exploit) # PUT YOUR DV 2ND (Y-AXIS)
plot(cont$moa_maturity, 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
## moa_maturity efficacy exploit row_id
## moa_maturity 1.00 0.17 -0.18 -0.01
## efficacy 0.17 1.00 -0.01 -0.02
## exploit -0.18 -0.01 1.00 0.00
## row_id -0.01 -0.02 0.00 1.00
## Sample Size
## [1] 3104
## Probability values (Entries above the diagonal are adjusted for multiple tests.)
## moa_maturity efficacy exploit row_id
## moa_maturity 0.0 0.00 0.00 1
## efficacy 0.0 0.00 1.00 1
## exploit 0.0 0.77 0.00 1
## row_id 0.5 0.29 0.95 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( exploit ~ moa_maturity + 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)
## moa_maturity efficacy
## 1.031075 1.031075
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)
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, 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 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) but we had issues with the normality of our residuals (by visually analyzing a Q-Q plot) and it deviates significantly, there no issues of multicollinearity among our two independent variables.
summary(reg_model)
##
## Call:
## lm(formula = exploit ~ moa_maturity + efficacy, data = cont)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.2968 -1.1594 -0.3342 0.8486 4.9129
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.38735 0.02416 98.810 <2e-16 ***
## moa_maturity -0.24662 0.02454 -10.051 <2e-16 ***
## efficacy 0.03579 0.02454 1.458 0.145
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.346 on 3101 degrees of freedom
## Multiple R-squared: 0.03157, Adjusted R-squared: 0.03095
## F-statistic: 50.55 on 2 and 3101 DF, p-value: < 2.2e-16
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 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 partially supported. The model was statistically significant, Adj. R2 = 1.35, F(2,3101) = 50.55, p< .001 . Our results indicate that maturity negatively predicts exploitativeness and had a small effect size ((0.10 < ß < 0.29); per Cohen, 1988), while self-efficacy does not significantly predict exploitativeness and had a trivial effect size (ß < 0.10). Full output from the regression model is reported in Table 1. This means that people’s exploitativeness decrease by 0.24 units for every one unit decrease in their exploitativeness, while it increased by 0.03 units for every one unit increase in their self-efficacy.
| Exploitativeness | ||||
|---|---|---|---|---|
| Predictors | Estimates | SE | CI | p |
| Intercept | 2.39 | 0.02 | 2.34 – 2.43 | <0.001 |
| Maturity | -0.25 | 0.02 | -0.29 – -0.20 | <0.001 |
| Self-Efficacy | 0.04 | 0.02 | -0.01 – 0.08 | 0.145 |
| Observations | 3104 | |||
| R2 / R2 adjusted | 0.032 / 0.031 | |||
References
Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.