library(resampledata)
For CO\( _2 \) example:
library(resampledata)
linearfit <- lm(Level~Year, data=Maunaloa)
plot(Maunaloa$Year, resid(linearfit))
abline(h=0)
Create the residual plot for the BB example.
bbfit <- lm(PercFG~OffReb, data=NBA1617)
plot(NBA1617$OffReb, resid(bbfit))
abline(h=0)
library(resampledata)
linearfit <- lm(Level~Year, data=Maunaloa)
plot(Maunaloa$Year, resid(linearfit))
abline(h=0)
lines(smooth.spline(Maunaloa$Year, resid(linearfit), df=3))
bbfit <- lm(PercFG~OffReb, data=NBA1617)
plot(NBA1617$OffReb, resid(bbfit))
#abline(h=0)
lines(smooth.spline(NBA1617$OffReb, resid(bbfit), df=3))
plot(Maunaloa$Level~Maunaloa$Year)
abline(linearfit)
library(resampledata)
library(tidyverse)
head(Alelager)
ID Type Alcohol Calories
1 1 Ale 5.50 160
2 2 Ale 5.40 156
3 3 Ale 4.85 146
4 4 Ale 4.50 150
5 5 Ale 5.20 160
6 6 Ale 5.30 174
Alelager %>%
select(Alcohol, Calories) %>%
plot
newbeer <- Alelager %>%
filter(Alcohol<6.5)
newbeer%>%
select(Alcohol, Calories) %>%
plot
r <- newbeer %>%
select(Alcohol, Calories) %>%
cor
r
Alcohol Calories
Alcohol 1.0000000 0.6105981
Calories 0.6105981 1.0000000
r^2
Alcohol Calories
Alcohol 1.00000 0.37283
Calories 0.37283 1.00000
linearbeer <- lm(Calories~Alcohol, data=newbeer)
linearbeer
Call:
lm(formula = Calories ~ Alcohol, data = newbeer)
Coefficients:
(Intercept) Alcohol
47.41 21.99
plot(newbeer$Alcohol, resid(linearbeer))
abline(h=0)
lines(smooth.spline(newbeer$Alcohol, resid(linearbeer), df=3))
confint(linearbeer)
2.5 % 97.5 %
(Intercept) -8.367596 103.19397
Alcohol 10.948288 33.02796
confint(bbfit)
2.5 % 97.5 %
(Intercept) 41.06394948 44.58278227
OffReb 0.03241561 0.08282798
library(ggformula)
gf_point(Calories~Alcohol, data=newbeer) %>%
gf_lm(interval="prediction", fill="skyblue") %>%
gf_lm(interval="confidence")
library(ggformula)
gf_point(PercFG~OffReb, data=NBA1617) %>%
gf_lm(interval="prediction", fill="skyblue") %>%
gf_lm(interval="confidence")
Calories.dist <- makeFun(linearbeer)
Calories.dist(Alcohol=5)
1
157.3538
Calories.dist(Alcohol=5, interval="confidence")
fit lwr upr
1 157.3538 153.3796 161.328
Calories.dist(Alcohol=5, interval="prediction")
fit lwr upr
1 157.3538 135.3588 179.3488
gf_point(Calories~Alcohol, data=newbeer) %>%
gf_lm(interval="prediction", fill="skyblue") %>%
gf_lm(interval="confidence")
Calories.dist(Alcohol=5)
1
157.3538
Calories.dist(Alcohol=5, interval="confidence")
fit lwr upr
1 157.3538 153.3796 161.328
Calories.dist(Alcohol=5, interval="prediction")
fit lwr upr
1 157.3538 135.3588 179.3488
FG.dist <- makeFun(bbfit)
FG.dist(OffReb=200)
1
54.34773
FG.dist(OffReb=200, interval="prediction")
fit lwr upr
1 54.34773 42.37505 66.3204