In: Statistics and Probability
Using the "mammals" dataset from the "MASS" library in R:
body brain
Arctic fox 3.385 44.50
Owl monkey 0.480 15.50
Mountain beaver 1.350 8.10
Cow 465.000 423.00
Grey wolf 36.330 119.50
Goat 27.660 115.00
Roe deer 14.830 98.20
Guinea pig 1.040 5.50
Verbet 4.190 58.00
Chinchilla 0.425 6.40
Ground squirrel 0.101 4.00
Arctic ground squirrel 0.920 5.70
African giant pouched rat 1.000 6.60
Lesser short-tailed shrew 0.005 0.14
Star-nosed mole 0.060 1.00
Nine-banded armadillo 3.500 10.80
Tree hyrax 2.000 12.30
N.A. opossum 1.700 6.30
Asian elephant 2547.000 4603.00
Big brown bat 0.023 0.30
Donkey 187.100 419.00
Horse 521.000 655.00
European hedgehog 0.785 3.50
Patas monkey 10.000 115.00
Cat 3.300 25.60
Galago 0.200 5.00
Genet 1.410 17.50
Giraffe 529.000 680.00
Gorilla 207.000 406.00
Grey seal 85.000 325.00
Rock hyrax-a 0.750 12.30
Human 62.000 1320.00
African elephant 6654.000 5712.00
Water opossum 3.500 3.90
Rhesus monkey 6.800 179.00
Kangaroo 35.000 56.00
Yellow-bellied marmot 4.050 17.00
Golden hamster 0.120 1.00
Mouse 0.023 0.40
Little brown bat 0.010 0.25
Slow loris 1.400 12.50
Okapi 250.000 490.00
Rabbit 2.500 12.10
Sheep 55.500 175.00
Jaguar 100.000 157.00
Chimpanzee 52.160 440.00
Baboon 10.550 179.50
Desert hedgehog 0.550 2.40
Giant armadillo 60.000 81.00
Rock hyrax-b 3.600 21.00
Raccoon 4.288 39.20
Rat 0.280 1.90
E. American mole 0.075 1.20
Mole rat 0.122 3.00
Musk shrew 0.048 0.33
Pig 192.000 180.00
Echidna 3.000 25.00
Brazilian tapir 160.000 169.00
Tenrec 0.900 2.60
Phalanger 1.620 11.40
Tree shrew 0.104 2.50
Red fox 4.235 50.40
The dataset needs to be log transformed to meet regression assumptions. Use predict() to calculate the confidence interval and regression line for this regression and graph it on both the log/log plot and on the un-transformed data (this will require that you back-transform the coordinates for the line and confidence intervals).
Here I attach the R code :
library("MASS")
data("mammals")
head(mammals)
m=lm(body~brain,data = mammals)
summary(m)
plot(m)
y=log(mammals$body,base = exp(1))
x=log(mammals$brain,base = exp(1))
m1=lm(y~x)
summary(m1)
r=residuals(m1)
shapiro.test(r)
Box.test(r,type="Ljung-Box")
plot(m1)
predict(m1, interval = "confidence")
fit lwr upr
1 2.14024328 1.9070219 2.3734646712
2 0.84834232 0.6201570 1.0765276865
3 0.05337401 -0.1918944 0.2986423892
4 4.89870541 4.5473461 5.2500647249
5 3.35029011 3.0783753 3.6222049320
retranformed form:
exp(predict(m1, interval = "confidence"))
fit lwr upr
1 8.501506e+00 6.733007e+00 1.073452e+01
2 2.335772e+00 1.859220e+00 2.934472e+00
3 1.054824e+00 8.253941e-01 1.348027e+00
4 1.341160e+02 9.438160e+01 1.905786e+02
5 2.851100e+01 2.172308e+01 3.741999e+01
The regression line is: Y= -2.509+1.225*X
The graph of log transformed data is:
plots of un transformed data is:
just run the R code to get each output.