Eamonn Mallon
28/02/2022
b <- seq(-1.43,-1,0.002)
sse <- numeric(length(b))
for (i in 1:length(b)) {
a <- mean(reg.data$growth)-b[i]*mean(reg.data$tannin)
residual <- reg.data$growth - a - b[i]*reg.data$tannin
sse[i] <- sum(residual^2)
}
plot(b,sse,type="l",ylim=c(19,24))
arrows(-1.216,20.07225,-1.216,19,col="red")
abline(h=20.07225,col="green",lty=2)
lines(b,sse)
print(b[which(sse==min(sse))])
[1] -1.216
\[ y = a + bx \] \[ a = y - bx \]
\[ a = \bar y - b\bar x \]
\[ y= 11.7 -1.2x \]
model <- lm(reg.data$growth~reg.data$tannin)
summary(model)
Call:
lm(formula = reg.data$growth ~ reg.data$tannin)
Residuals:
Min 1Q Median 3Q Max
-2.4556 -0.8889 -0.2389 0.9778 2.8944
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 11.7556 1.0408 11.295 9.54e-06 ***
reg.data$tannin -1.2167 0.2186 -5.565 0.000846 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.693 on 7 degrees of freedom
Multiple R-squared: 0.8157, Adjusted R-squared: 0.7893
F-statistic: 30.97 on 1 and 7 DF, p-value: 0.0008461
\[ y = 11.75 - 1.2x \] Tanin levels affect growth (Regression: \( R^2 \) = 0.79, \( F_{1,7} \) = 30.97, p = \( 0.0009 \))