In: Math
Use the R script to answer the following questions: (write down your answers in the R script with ##)
(1). Import FarmSize.csv to Rstudio. Use the correct function to build a linear regression model predicting the average size of a farm by the number of farms; Give the model a name (e.g. FarmSize_Model). Call the model name to inspect the intercept and slope of the regression model. Verify the answers in your manual calculation.
(2). Use the correct function to generate the residuals for the 12 examples in the dataset from the model. Create a residual plot, with x axis as independent variable and y axis as residual.
(3). Use the correct function to inspect SSE, Se and r². Write down the values for these measures. Verify the answers in your manual calculation.
(4). Use the correct function to inspect slope statistic testing result. What is the t value for the slope statistic testing? What is the p value? What is the statistical decision?
Year | NumberofFarms | AverageSize |
1950 | 5.65 | 213 |
1955 | 4.65 | 258 |
1960 | 3.96 | 297 |
1965 | 3.36 | 340 |
1970 | 2.95 | 374 |
1975 | 2.52 | 420 |
1980 | 2.44 | 426 |
1985 | 2.29 | 441 |
1990 | 2.15 | 460 |
1995 | 2.07 | 469 |
2000 | 2.17 | 434 |
2005 | 2.1 | 444 |
Ans :
1) R-code :
d=read.csv("C:/Users/Dell/Desktop/FarmSize.csv",header=TRUE);d
FarmSize_Model=lm(AverageSize~., data =d)
summary(FarmSize_Model)
Output:
Coefficients:
(Intercept) NumberofFarms
600.19 -72.33
AverageSize = 600.19 -72.33 *NumberofFarms
2) Residuals for the 12 examples R -code
FarmSize_Model$residuals[12]
Output:
-4.297088
Residual plot where, x axis as independent variable and y axis as residual.
R-plot :
For image 1)
FarmSize_Model1=lm(NumberofFarms~., data =d)
summary(FarmSize_Model1)
plot(FarmSize_Model1)
For image 2)
plot(FarmSize_Model)
3) R-code :
summary(FarmSize_Model)
Output :
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 600.186 11.711 51.25 1.93e-13 ***
NumberofFarms -72.328 3.631 -19.92 2.24e-09 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 14.03 on 10 degrees of freedom
Multiple R-squared: 0.9754, Adjusted R-squared: 0.973
F-statistic: 396.7 on 1 and 10 DF, p-value: 2.235e-09
4) R- code :
summary(FarmSize_Model)
Ans :Hypothesis
Ho: Β1 = 0
Ha: Β1 ≠ 0
t-value for the slope statistic testing = -19.92
p value = 4.48e-09
statistical decision : p-value is less than significance level so we reject the null hypothesis. i.e. slope of the equation is not equal to zero.