Reviewing the car price models.
cars1 = fetchGoogle("https://docs.google.com/spreadsheet/pub?key=0Akkdc3QLDbyAdGxNRDAzcG5aRGJBSVFHa3ljaHVObnc&output=csv")
## Loading required package: RCurl
## Loading required package: bitops
confint(lm(Price ~ Age, data = cars1))
## 2.5 % 97.5 %
## (Intercept) 20312 48002
## Age -4309 -1023
confint(lm(Price ~ Miles, data = cars1))
## 2.5 % 97.5 %
## (Intercept) 19382.186 2.696e+04
## Miles -0.123 -6.394e-02
confint(lm(Price ~ Age + Miles, data = cars1))
## 2.5 % 97.5 %
## (Intercept) 22949.5370 3.886e+04
## Age -2289.1924 -7.577e+01
## Miles -0.1064 -4.523e-02
Construct models using Zip, Age, Miles and discuss the units. What happens with interaction terms? What are the units of those?
prius = fetchData("M155/Spring2013/ToyotaPrius.csv")
## Retrieving from
## http://www.mosaic-web.org/go/datasets/M155/Spring2013/ToyotaPrius.csv
lm(Price ~ Age, data = prius)
## Error: object 'Age' not found
What does the intercept mean? Price of a hypothetical prius produced in year 0 — the Roman prius (not to be confused with Priapus).
prius = transform(prius, Age = 2013 - Year)
mod = lm(Price ~ Age + Miles, data = prius)
mod
##
## Call:
## lm(formula = Price ~ Age + Miles, data = prius)
##
## Coefficients:
## (Intercept) Age Miles
## 2.64e+04 -1.78e+03 -1.71e-02
# make a 2-d plot of this
f1 = makeFun(mod)
plotFun(f(Age = a, Miles = m) ~ a & m, a.lim = c(0, 10), m.lim = c(0, 1e+05))
## Error: could not find function "f"
lm(Price ~ Age + Miles + Zip, data = prius)
##
## Call:
## lm(formula = Price ~ Age + Miles + Zip, data = prius)
##
## Coefficients:
## (Intercept) Age Miles Zipz55347 Zipz78717
## 2.62e+04 -1.85e+03 -1.29e-02 -5.94e+02 1.50e+01
## Zipz90210
## 1.63e+03
lm(Price ~ Age + Miles * Zip, data = prius)
##
## Call:
## lm(formula = Price ~ Age + Miles * Zip, data = prius)
##
## Coefficients:
## (Intercept) Age Miles Zipz55347
## 2.45e+04 -1.64e+03 1.40e-03 1.85e+03
## Zipz78717 Zipz90210 Miles:Zipz55347 Miles:Zipz78717
## 2.31e+03 3.73e+03 -4.58e-02 -4.41e-02
## Miles:Zipz90210
## -4.31e-02
mod = lm(Price ~ Age * Miles, data = prius)
f = makeFun(mod)
plotFun(f(Age = a, Miles = m) ~ a & m, a.lim = c(0, 10), m.lim = c(0, 1e+05))
max(Miles, data = prius)
## [1] 328000
pp = subset(prius, Miles < 1e+05)
mod = lm(Price ~ Age * Miles, data = pp)
f = makeFun(mod)
plotFun(f(Age = a, Miles = m) ~ a & m, a.lim = c(0, 10), m.lim = c(0, 1e+05))