Chapter 17 FAQs
Why am I getting weird variable names?
Unfortunately this can happen on windows computers.You can fix it with the following code
This code looks at the column names, picks the first one, and then reassigns it to Age.
How do I produce a residual plot with missing values in data?
library(ggplot2)
help(msleep)
plot(sleep$bodywt, sleep$brainwt)
L = lm(sleep$brainwt ~ sleep$bodywt)
summary(L)
abline(L)
# Correlation (with missing values)
length(sleep$bodywt)
length(sleep$brainwt)
cor(sleep$bodywt, sleep$brainwt, use = "complete.obs")
# Residual plot (with missing values)
length(sleep$bodywt)
length(L$residuals)
residuals1 = resid(lm(sleep$brainwt ~ sleep$bodywt, na.action=na.exclude))
length(residuals1)
plot(sleep$bodywt,residuals1)