In: Math
Listed below are the log body weights and log brain weights of the primates species in the data set ”mammals”. Find the equation of the least squares line with y = log brain weight and x = log body weight. Do it by hand, by constructing a table like the one in Example 9.1. Then do it with your calculator as efficiently as possible. Finally, use the lm function in R to do it by creating a linear model object ”primates.lm”. The model formula is ”log(brain)∼log(body)”. You can select the primates and put them in a new data frame by first listing the primate species names:
> primatenames=c(”Owl monkey”, ”Patas monkey”, ”Gorilla”, etc.)
and then
> primates=mammals[primatenames, ]
Your ”data” argument in calling lm would be ”data=primates”, as in
> primates.lm=lm(log(brain)∼log(body),data=primates)
Alternatively, you can just use ”mammals[primatenames, ]” as the data argument in lm, that is,
> primates.lm=lm(log(brain)∼log(body), data=mammals[primatenames,])
log body log brain
Owl monkey -0.7339692 2.740840
Patas monkey 2.3025851 4.744932
Gorilla 5.3327188 6.006353
Human 4.1271344 7.185387
Rhesus monkey 1.9169226 5.187386
Chimpanzee 3.9543159 6.086775
Baboon 2.3561259 5.190175
Verbet 1.4327007 4.060443
Galago -1.6094379 1.609438
Slow loris 0.3364722 2.525729
The dataset is not given hence we use the mammalssleep data set ,
the r code is as below
data("mammalsleep")
primatenames <- c("Owl monkey", "Patas monkey", "Gorilla")
primates= mammalsleep %>% filter(species %in%
primatenames)
#Your ”data” argument in calling lm would be ”data=primates”, as
in
primates.lm=lm(log(brw)~log(bw),data=primates)
summary(primates.lm)
The results of the regression is
summary(primates.lm)
Call:
lm(formula = log(brw) ~ log(bw), data = primates)
Residuals:
1 2 3
-0.1233 -0.1231 0.2464
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.25902 0.23780 13.705 0.0464 *
log(bw) 0.53831 0.07035 7.652 0.0827 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.3018 on 1 degrees of freedom
Multiple R-squared: 0.9832, Adjusted R-squared: 0.9664
F-statistic: 58.55 on 1 and 1 DF, p-value: 0.08273
The regression equation is formed using the
as
log(brw) = 3.25 +0.5383*log(bw)
the r2 value is 0.9832 , this means that the model is very good, higher the value better the model range is 0 to 1
also note that r2 means that about 98.32 % variation in data is explained by the model