#Adding a power term (quadratic) to regression via Aiken & West mean centering or residual centering

#Aiken and West test of quadratic effect of IV1

Wk10nm$c_IV1 <- Wk10nm$IV1 - mean(Wk10nm$IV1)
Wk10nm$c_IV1sq <- Wk10nm$c_IV1^2


fit2 <- lm(DV1 ~ IV1 + c_IV1sq, data=Wk10nm)
summary(fit2) # show results
## 
## Call:
## lm(formula = DV1 ~ IV1 + c_IV1sq, data = Wk10nm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.130 -9.650 0.110 9.177 32.168
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 31.034791 2.210865 14.037 <2e-16 ***
## IV1 0.333432 0.033575 9.931 <2e-16 ***
## c_IV1sq 0.002338 0.001349 1.733 0.0846 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.88 on 197 degrees of freedom
## Multiple R-squared: 0.3437, Adjusted R-squared: 0.3371
## F-statistic: 51.59 on 2 and 197 DF, p-value: < 2.2e-16
confint(fit2, level=0.95) # CIs for model parameters 
##                     2.5 %       97.5 %
## (Intercept) 26.6747903964 35.394791286
## IV1 0.2672186455 0.399645615
## c_IV1sq -0.0003224178 0.004998864
library(QuantPsyc)
lm.beta(fit2)
##       IV1   c_IV1sq 
## 0.5736473 0.1001114
#Residual centering test of quadratic effect of IV1

Wk10nm$IV1sq<-Wk10nm$IV1^2

fit3 <- lm(IV1sq ~ IV1, data=Wk10nm)

#The two steps below save the residual back to your data frame

Wk10nm$IV1sq_resid <- NA

Wk10nm$IV1sq_resid <- fit3$resid

#residual centering approach

fit4 <- lm(DV1 ~ IV1 + IV1sq_resid, data=Wk10nm)
summary(fit4) # show results
## 
## Call:
## lm(formula = DV1 ~ IV1 + IV1sq_resid, data = Wk10nm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.130 -9.650 0.110 9.177 32.168
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 32.920507 1.924591 17.105 <2e-16 ***
## IV1 0.335789 0.033548 10.009 <2e-16 ***
## IV1sq_resid 0.002338 0.001349 1.733 0.0846 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.88 on 197 degrees of freedom
## Multiple R-squared: 0.3437, Adjusted R-squared: 0.3371
## F-statistic: 51.59 on 2 and 197 DF, p-value: < 2.2e-16
confint(fit4, level=0.95) # CIs for model parameters 
##                     2.5 %       97.5 %
## (Intercept) 29.1250606729 36.715953439
## IV1 0.2696295262 0.401947855
## IV1sq_resid -0.0003224178 0.004998864
lm.beta(fit4)
##         IV1 IV1sq_resid 
## 0.5777016 0.1000293