library(haven)
curvreg_data <- read_sav("curvilinear_practice(1).sav")
head(curvreg_data)
## # A tibble: 6 x 4
## y_score x_pratice practice_squared practice_cubed
## <dbl> <dbl> <dbl> <dbl>
## 1 4 2 4 8
## 2 6 2 4 8
## 3 5 2 4 8
## 4 7 4 16 64
## 5 10 4 16 64
## 6 10 4 16 64
Below, you will find two examples of a scatterplot, with and without a fit line
# Plot a Scatterplot between IV and DV
plot(curvreg_data$x_pratice,curvreg_data$y_score, main="Scatterplot between Practice Time and Task Score",xlab="Practice Time",ylab="Task Score")
# Run a linear regression model by using lm() function
curvreg_lm <- lm(y_score~x_pratice,data=curvreg_data)
summary(curvreg_lm)
##
## Call:
## lm(formula = y_score ~ x_pratice, data = curvreg_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.7424 -1.6130 0.1245 0.9356 5.6245
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.8646 1.0772 3.588 0.0021 **
## x_pratice 1.4389 0.1274 11.295 1.33e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.112 on 18 degrees of freedom
## Multiple R-squared: 0.8764, Adjusted R-squared: 0.8695
## F-statistic: 127.6 on 1 and 18 DF, p-value: 1.329e-09
# Add linear fit lines
plot(y_score~x_pratice,data=curvreg_data)
abline(lm(y_score~x_pratice,data=curvreg_data))
## Quadratic regression model
#Quadratic regression model by using lm() function
curvreg_Quadm <- lm(y_score~x_pratice+practice_squared,data=curvreg_data)
summary(curvreg_Quadm)
##
## Call:
## lm(formula = y_score ~ x_pratice + practice_squared, data = curvreg_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.8418 -0.6870 -0.1126 0.6913 3.8206
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.77726 1.36506 -1.302 0.210296
## x_pratice 3.43995 0.42058 8.179 2.7e-07 ***
## practice_squared -0.13380 0.02754 -4.858 0.000148 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.406 on 17 degrees of freedom
## Multiple R-squared: 0.9482, Adjusted R-squared: 0.9421
## F-statistic: 155.7 on 2 and 17 DF, p-value: 1.175e-11
# Add quadratic fit lines
library(ggplot2)
ggplot(curvreg_data, aes(x=x_pratice, y=y_score)) + geom_point()+stat_smooth(se=F, method='lm', formula=y~poly(x,2))
## Cubic regression model
curvreg_cubreg <- lm(y_score~x_pratice+practice_squared+practice_cubed,data=curvreg_data)
summary(curvreg_cubreg)
##
## Call:
## lm(formula = y_score ~ x_pratice + practice_squared + practice_cubed,
## data = curvreg_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.6033 -0.7887 0.0367 0.5494 3.7376
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.3653250 2.7034153 -0.135 0.894
## x_pratice 2.5878285 1.4631647 1.769 0.096 .
## practice_squared 0.0002056 0.2217818 0.001 0.999
## practice_cubed -0.0060313 0.0099021 -0.609 0.551
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.433 on 16 degrees of freedom
## Multiple R-squared: 0.9494, Adjusted R-squared: 0.9399
## F-statistic: 100.1 on 3 and 16 DF, p-value: 1.403e-10
# Add fit lines
ggplot(curvreg_data, aes(x=x_pratice, y=y_score)) + geom_point()+stat_smooth(se=F, method='lm', formula=y~poly(x,3))
# Section 3. Model Comparison
anova(curvreg_lm,curvreg_Quadm) # Compare linear with quadratic regression model
## Analysis of Variance Table
##
## Model 1: y_score ~ x_pratice
## Model 2: y_score ~ x_pratice + practice_squared
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 18 80.273
## 2 17 33.614 1 46.659 23.597 0.0001477 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(curvreg_Quadm,curvreg_cubreg) # Compare quadratic with cubic regression model
## Analysis of Variance Table
##
## Model 1: y_score ~ x_pratice + practice_squared
## Model 2: y_score ~ x_pratice + practice_squared + practice_cubed
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 17 33.614
## 2 16 32.852 1 0.76176 0.371 0.551
anova(curvreg_lm,curvreg_cubreg) # Compare linear with cubic regression model
## Analysis of Variance Table
##
## Model 1: y_score ~ x_pratice
## Model 2: y_score ~ x_pratice + practice_squared + practice_cubed
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 18 80.273
## 2 16 32.852 2 47.421 11.548 0.000787 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The linear, quadratic, and curvillinear models accurately predict the outcome (score) to the alpha .05 level. However a blockwise curvilienear regression reveals that there is a significant increase in r-square change between the linear and quadratic models F(2,16)= 11.58, p <.05, but there was no significant difference between the quadratic and curvilinear models (p>.05). The regression can thus be described by the following quadratic equation:
Y = -1.78 + 3.44(x) + -.13(x)^2
Exoected performance by someone who practices for 8 hours is 17.42 points. answer <- -1.78 + 3.44x8 + -.13x8^2