I'm looking to test explanatory variables that might have quadratic rather than linear relation to the dependent variable. I have read in several places that this could be done using the squared (^2) values of the explanatory variables. However, in all the examples I found online, as well as for my analysis, results for both linear and quadratic regressions were significant (though sometimes opposite -/+).
I can see how both could be correct sometimes but just in case I ran it on a dataset that is obviously linear:
Var1 <- seq(1:51)
Var2 <- seq(0, 1, 0.02)
Var3 <- Var2^2
Test <- data.frame(cbind(Var1, Var2, Var3))
plot(Test$Var2, Test$Var1)
summary(lm(Var1 ~ Var2 + Var3, Test))
Call:
lm(formula = Var1 ~ Var2 + Var3, data = Test)
Residuals:
Min 1Q Median 3Q Max
-3.801e-14 -1.868e-15 2.200e-17 3.997e-15 1.222e-14
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.000e+00 3.099e-15 3.227e+14 <2e-16 ***
Var2 5.000e+01 1.433e-14 3.489e+15 <2e-16 ***
Var3 -3.977e-14 1.386e-14 -2.869e+00 0.0061 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 7.668e-15 on 48 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: 1
F-statistic: 9.395e+31 on 2 and 48 DF, p-value: < 2.2e-16
Can anyone explain how is this possible and how should I approach it? What are the circumstances where it should and shouldn't be used?
**Edit: When i run the regression with only the quadratic variable such as
summary(lm(Var1~Var3, data = Test))
I get this result
Call:
lm(formula = Var1 ~ Var3, data = Test)
Residuals:
Min 1Q Median 3Q Max
-9.257 -2.645 1.077 3.317 4.107
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 10.2569 0.7979 12.86 <2e-16 ***
Var3 46.7616 1.7580 26.60 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.822 on 49 degrees of freedom
Multiple R-squared: 0.9352, Adjusted R-squared: 0.9339
F-statistic: 707.5 on 1 and 49 DF, p-value: < 2.2e-16
Can anyone explain the logic of the regression I think I'm missing?