I generated one data
treatment<- c(0,24,36,48)
yield<- c(4.78,9.67,8.02,6.7)
dataA<- data.frame(treatment, yield)
Then I did draw a curvilinear graph.
ggplot(data=dataA, aes(x=treatment, y=yield))
stat_smooth(method='lm', linetype=1, se=FALSE, formula=y~poly(x,2),
size=0.5, color="Blue")
geom_point (col="Black", size=4)
scale_y_continuous(breaks = seq(0,12,2), limits = c(0,12))
labs(x="Fertilizer application (kg/ha)", y="Yield (ton/ha)")
theme_classic(base_size=18, base_family="serif")
theme(axis.line= element_line(size=0.5, colour="black"))
windows(width=5.5, height=5)
Also, I analyzed statistical significance.
regression<- lm(yield ~ poly(treatment,2), data=dataA)
summary(regression)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.2925 0.4376 16.663 0.0382 *
poly(treatment, 2)1 1.5441 0.8753 1.764 0.3283
poly(treatment, 2)2 -3.1137 0.8753 -3.557 0.1745
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.8753 on 1 degrees of freedom
Multiple R-squared: 0.9404, Adjusted R-squared: 0.8211
F-statistic: 7.884 on 2 and 1 DF, p-value: 0.2442
When I checked the equation model in Excel, the model equation was y = -0.006x2 0.3234x 4.8742
but in R, it says y=-3.1137x2 1.5441x 7.2925
Why the model equation is different between Excel and R? Which equation is correct?
To analyze curvilinear, the code, yield ~ poly(treatment,2)
would be wrong?
Could you let me know about this?
[Excel]
Thanks,
CodePudding user response:
The Excel and R regressions are not equivalent.
The poly
function in R computes orthogonal polynomials by default. In order for the regression to be the same as the Excel equation, you can set the raw
argument to TRUE
:
regression<- lm(yield ~ poly(treatment, 2, raw = TRUE), data=dataA)
summary(regression)
Output:
Call:
lm(formula = yield ~ poly(treatment, 2, raw = TRUE), data = dataA)
Residuals:
1 2 3 4
-0.08345 0.50073 -0.66764 0.25036
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.863455 0.871291 5.582 0.113
poly(treatment, 2, raw = TRUE)1 0.325773 0.083092 3.921 0.159
poly(treatment, 2, raw = TRUE)2 -0.006098 0.001714 -3.557 0.174
Residual standard error: 0.8753 on 1 degrees of freedom
Multiple R-squared: 0.9404, Adjusted R-squared: 0.8211
F-statistic: 7.884 on 2 and 1 DF, p-value: 0.2442