hubble <- read.table("../data/hubble.dat", header=TRUE)
str(hubble)
with(hubble, plot(velocity ~ distance))
lm_hubble <- lm(velocity ~ distance, data=hubble)
lm_hubble # print(lm_hubble)
summary(lm_hubble)
# str(lm_hubble)
par(mfrow=c(2,2))
plot(lm_hubble) # Tuckey's diagnostic plots
ozdata = read.table("../data/ozone.csv", header=TRUE, sep=",")
head(ozdata)
lm_oz = lm(Ozone ~ Wind + Temp, data=ozdata)
summary(lm_oz)
lm_oz = lm(Ozone ~ Wind + Temp + Solar.R, data=ozdata)
summary(lm_oz)
plot(lm_oz$residuals, type="h")
points(lm_oz$residuals)
grid()
All statistical models in R can be utilized for prediction, using the predict()
function.
predict(lm_oz, newdata = data.frame(Wind=c(10,11,12), Temp=c(60,61,62), Solar.R=rep(100, 3)))
Model formulae will b accepted by many functions in R and R packages.
y ~ .
y ~ x
y ~ x - 1
y ~ x1 + x2 + ...
y ~ x1 * x2
y ~ x + I(x^2)
log(y) ~ x # y = exp(a + b x)
...
plasma <- read.table("../data/plasma.dat", header=TRUE)
str(plasma)
plot(plasma$ESR)
plasma_glm <- glm(ESR ~ fibrinogen + globulin, data=plasma, family="binomial")
summary(plasma_glm)
prob <- predict(plasma_glm, plasma[, 1:2], type="response")
plot(prob ~ plasma$ESR)
plot(plasma$fibri, plasma$globu, pch='x', col=plasma$ESR,
xlim=c(2,6), ylim=c(25,55))
symbols(plasma$fibri, plasma$globu, circles=prob, add=TRUE)
...