install.packages("Stat2Data")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
library(Stat2Data)
data(Cereal)
attach(Cereal)
## The following object is masked _by_ .GlobalEnv:
##
## Cereal
cereal.lm = lm(Calories~Sugar)
plot(Calories~Sugar, main="Calories v. Sugar", xlab= "Sugar",ylab ="Calories")
abline(cereal.lm)
plot(cereal.lm$fitted.values,cereal.lm$residuals,main="Residual Plot",ylab="Residuals",xlab="Predicted Calories")
abline(0,0)
hist(cereal.lm$residuals)
### normal plot
qqnorm(cereal.lm$residuals)
qqline(cereal.lm$residuals)
summary(cereal.lm)
##
## Call:
## lm(formula = Calories ~ Sugar)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.428 -9.832 0.245 8.909 40.322
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 87.4277 5.1627 16.935 <2e-16 ***
## Sugar 2.4808 0.7074 3.507 0.0013 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 19.27 on 34 degrees of freedom
## Multiple R-squared: 0.2656, Adjusted R-squared: 0.244
## F-statistic: 12.3 on 1 and 34 DF, p-value: 0.001296