# reading the data
d = read.table("C:/Users/Sima/Desktop/Regression/Akbar.txt", header= TRUE, sep=",")
# looking in to data
str(d)
## 'data.frame': 100 obs. of 4 variables:
## $ x0: int 1 2 3 4 5 6 7 8 9 10 ...
## $ x1: num 72.7 80.6 83.9 79.4 69 ...
## $ x2: num 3.42 8.6 1.11 5.32 5.54 ...
## $ y : num 597.1 56.1 834.7 442.1 357.4 ...
# Part a: Scatter plot matrix
plot(~x0+x1+x2+y, data=d)
# Part b: Fit model
yb.lm=lm(y~x1+x2, data=d)
summary(yb.lm)
##
## Call:
## lm(formula = y ~ x1 + x2, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -99.642 -16.770 8.192 24.180 41.061
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 369.5516 44.7043 8.267 7.26e-13 ***
## x1 7.7613 0.5802 13.377 < 2e-16 ***
## x2 -104.2501 1.6912 -61.642 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 33.57 on 97 degrees of freedom
## Multiple R-squared: 0.9766, Adjusted R-squared: 0.9762
## F-statistic: 2028 on 2 and 97 DF, p-value: < 2.2e-16
anova(yb.lm)
## Analysis of Variance Table
##
## Response: y
## Df Sum Sq Mean Sq F value Pr(>F)
## x1 1 287754 287754 255.27 < 2.2e-16 ***
## x2 1 4283247 4283247 3799.75 < 2.2e-16 ***
## Residuals 97 109343 1127
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Part c: Fit model
d$x1s <- (d$x1)^2
d$x2s <- (d$x2)^2
d$x1x2 <- (d$x1)*(d$x2)
yc.lm=lm(y~x1+x1s+x2+x2s+x1x2, data=d)
summary(yc.lm)
##
## Call:
## lm(formula = y ~ x1 + x1s + x2 + x2s + x1x2, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -27.100 -10.513 1.864 12.048 20.801
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 137.92799 278.35483 0.496 0.621
## x1 7.39533 7.42368 0.996 0.322
## x1s 0.02057 0.04942 0.416 0.678
## x2 2.39802 9.02217 0.266 0.791
## x2s -6.02503 0.27850 -21.634 < 2e-16 ***
## x1x2 -0.57812 0.11058 -5.228 1.03e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.73 on 94 degrees of freedom
## Multiple R-squared: 0.9962, Adjusted R-squared: 0.996
## F-statistic: 4950 on 5 and 94 DF, p-value: < 2.2e-16
anova(yc.lm)
## Analysis of Variance Table
##
## Response: y
## Df Sum Sq Mean Sq F value Pr(>F)
## x1 1 287754 287754 1527.353 < 2.2e-16 ***
## x1s 1 19323 19323 102.565 < 2.2e-16 ***
## x2 1 4265593 4265593 22641.079 < 2.2e-16 ***
## x2s 1 84814 84814 450.178 < 2.2e-16 ***
## x1x2 1 5150 5150 27.334 1.031e-06 ***
## Residuals 94 17710 188
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Part d: Standardize the predictors
d$z1 = (d$x1-mean(d$x1))/sd(d$x1)
d$z2 = (d$x2-mean(d$x2))/sd(d$x2)
d$z1s <- (d$z1)^2
d$z2s <- (d$z2)^2
d$z1z2 <- (d$z1)*(d$z2)
yd.lm=lm(y~z1+z1s+z2+z2s+z1z2, data=d)
summary(yd.lm)
##
## Call:
## lm(formula = y ~ z1 + z1s + z2 + z2s + z1z2, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -27.100 -10.513 1.864 12.048 20.801
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 435.6928 2.2871 190.500 < 2e-16 ***
## z1 43.6158 1.3852 31.487 < 2e-16 ***
## z1s 0.6968 1.6743 0.416 0.678
## z2 -205.3530 1.3926 -147.461 < 2e-16 ***
## z2s -24.0275 1.1106 -21.634 < 2e-16 ***
## z1z2 -6.7202 1.2854 -5.228 1.03e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.73 on 94 degrees of freedom
## Multiple R-squared: 0.9962, Adjusted R-squared: 0.996
## F-statistic: 4950 on 5 and 94 DF, p-value: < 2.2e-16
# Part e
# Load DAAG library
library("DAAG")
## Warning: package 'DAAG' was built under R version 3.3.3
## Loading required package: lattice
## Warning: package 'lattice' was built under R version 3.3.3

# Fit the model and look at the summary for it
ye.lm=lm(y~z1+z2+z2s+z1z2, data=d)
summary(ye.lm)
##
## Call:
## lm(formula = y ~ z1 + z2 + z2s + z1z2, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26.407 -10.792 1.792 12.048 21.187
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 436.307 1.739 250.872 < 2e-16 ***
## z1 43.590 1.378 31.637 < 2e-16 ***
## z2 -205.338 1.386 -148.147 < 2e-16 ***
## z2s -23.952 1.091 -21.954 < 2e-16 ***
## z1z2 -6.742 1.279 -5.272 8.43e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.67 on 95 degrees of freedom
## Multiple R-squared: 0.9962, Adjusted R-squared: 0.996
## F-statistic: 6241 on 4 and 95 DF, p-value: < 2.2e-16
# Look at anova table to get MSE
# 5-fold Cross Validation
cv5res=cv.lm(data=d, ye.lm, m=5)
## Analysis of Variance Table
##
## Response: y
## Df Sum Sq Mean Sq F value Pr(>F)
## z1 1 287754 287754 1540.8 < 2e-16 ***
## z2 1 4283247 4283247 22934.4 < 2e-16 ***
## z2s 1 86409 86409 462.7 < 2e-16 ***
## z1z2 1 5191 5191 27.8 8.4e-07 ***
## Residuals 95 17742 187
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = d, ye.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 20
## 1 12 14 20 29 32 38 40 52
## Predicted 579.1 601.0 414.2 91.1 324.9 254.21 373.22 192.38 433.03
## cvpred 578.5 599.3 414.7 91.1 325.6 253.84 372.11 192.94 431.86
## y 597.1 619.5 426.9 71.7 313.3 256.72 363.09 199.76 427.01
## CV residual 18.6 20.2 12.2 -19.4 -12.4 2.88 -9.01 6.82 -4.85
## 57 60 66 69 72 81 83 86 91 96
## Predicted 195.7 319.07 530.467 581.54 805.4 236.6 739.0 759.0 408.74 475
## cvpred 195.5 317.99 529.218 582.66 801.0 235.9 735.6 757.3 408.21 475
## y 212.7 327.93 529.994 581.19 811.4 256.4 758.1 751.1 401.70 460
## CV residual 17.2 9.94 0.777 -1.48 10.4 20.5 22.4 -6.2 -6.52 -16
## 98
## Predicted 504.03
## cvpred 503.24
## y 509.64
## CV residual 6.39
##
## Sum of squares = 3397 Mean square = 170 n = 20
##
## fold 2
## Observations in test set: 20
## 3 8 15 16 17 18 23 28 31 33
## Predicted 843 366.4 466.26 463.0 342.0 91.5 245.4 334.85 681.1 495.5
## cvpred 845 367.1 467.11 463.0 343.7 93.6 245.7 335.11 683.1 495.7
## y 835 343.5 461.94 481.6 316.8 72.3 260.8 338.47 661.8 475.0
## CV residual -10 -23.7 -5.17 18.6 -26.9 -21.3 15.1 3.37 -21.3 -20.7
## 39 42 45 48 58 59 62 63 90 100
## Predicted 539.3 -82.81 331.85 150.3 415.1 591.9 622.94 424.2 44.4 99.0
## cvpred 539.8 -79.35 332.62 153.3 415.8 592.3 623.26 424.2 46.2 105.1
## y 550.1 -77.58 329.41 133.2 400.0 603.5 628.19 442.6 28.0 76.4
## CV residual 10.3 1.77 -3.21 -20.2 -15.8 11.2 4.93 18.4 -18.2 -28.6
##
## Sum of squares = 5745 Mean square = 287 n = 20
##
## fold 3
## Observations in test set: 20
## 4 5 9 10 13 19 27 30 36 46
## Predicted 453.1 353.99 475.6 431.2 466.2 445.8 400.0 27.7 577 568.235
## cvpred 453.3 354.94 476.5 432.2 466.3 445.9 400.0 27.8 577 568.639
## y 442.1 357.37 493.0 445.9 453.9 458.3 421.1 45.5 592 568.814
## CV residual -11.2 2.43 16.5 13.7 -12.4 12.4 21.2 17.8 15 0.176
## 47 49 55 61 70 78 82 92 93
## Predicted -263.65 574.2 79.4 587.1 1.85 614.32 443.1 456.1 233.9
## cvpred -264.66 576.1 79.5 587.4 1.48 614.46 444.2 456.8 234.7
## y -260.17 556.8 59.9 565.9 -4.30 610.63 422.7 437.9 218.4
## CV residual 4.48 -19.3 -19.6 -21.5 -5.79 -3.83 -21.4 -18.9 -16.4
## 94
## Predicted 563.73
## cvpred 564.00
## y 565.86
## CV residual 1.86
##
## Sum of squares = 4265 Mean square = 213 n = 20
##
## fold 4
## Observations in test set: 20
## 7 25 26 35 43 54 56 67 68
## Predicted 702.16 323.144 653.23 551.1 421.7 103.36 592.02 367.9 358.3
## cvpred 702.05 322.906 653.00 550.9 421.5 102.41 591.86 367.6 357.8
## y 700.39 323.131 657.76 561.5 436.9 106.08 595.68 381.7 377.0
## CV residual -1.65 0.225 4.76 10.6 15.4 3.67 3.82 14.1 19.1
## 73 74 76 77 84 85 87 88 89 97
## Predicted 588.69 311.64 651.1 496.5 -84.90 170.2 571.7 527 743.26 481.4
## cvpred 588.57 311.15 650.9 496.3 -85.86 169.4 571.5 527 743.12 481.3
## y 580.28 307.71 640.3 508.1 -76.63 163.8 558.7 545 748.34 458.5
## CV residual -8.29 -3.44 -10.6 11.8 9.23 -5.6 -12.8 18 5.22 -22.8
## 99
## Predicted 399
## cvpred 399
## y 382
## CV residual -17
##
## Sum of squares = 2740 Mean square = 137 n = 20
##
## fold 5
## Observations in test set: 20
## 2 6 11 21 22 24 34 37 41 44
## Predicted 42.8 428.3 221.24 619.0 600.8 656.69 301.16 532 222.5 383.22
## cvpred 37.2 428.6 220.62 621.4 603.2 656.00 300.16 529 219.2 381.97
## y 56.1 418.4 228.55 592.6 596.1 651.69 293.24 550 241.1 386.91
## CV residual 18.9 -10.2 7.93 -28.9 -7.1 -4.31 -6.92 21 21.9 4.94
## 50 51 53 64 65 71 75 79 80
## Predicted 521.44 547.6 606.5 603.9 335.3 468.34 613.28 708.99 -36.2
## cvpred 522.36 547.5 605.7 603.0 334.4 466.35 609.21 701.99 -41.2
## y 519.61 536.6 621.3 615.8 348.0 470.91 617.29 710.44 -19.0
## CV residual -2.75 -10.9 15.6 12.8 13.6 4.56 8.08 8.46 22.2
## 95
## Predicted 210.344
## cvpred 209.240
## y 208.249
## CV residual -0.991
##
## Sum of squares = 3794 Mean square = 190 n = 20
##
## Overall (Sum over all 20 folds)
## ms
## 199
# part f
# Fit the model and look at the summary for it
yf.lm=lm(y~x1+x2+x2s+x1x2, data=d)
summary(yf.lm)
##
## Call:
## lm(formula = y ~ x1 + x2 + x2s + x1x2, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26.41 -10.79 1.79 12.05 21.19
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 23.782 47.303 0.50 0.62
## x1 10.474 0.620 16.89 < 2e-16 ***
## x2 2.350 8.982 0.26 0.79
## x2s -6.006 0.274 -21.95 < 2e-16 ***
## x1x2 -0.580 0.110 -5.27 8.4e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.7 on 95 degrees of freedom
## Multiple R-squared: 0.996, Adjusted R-squared: 0.996
## F-statistic: 6.24e+03 on 4 and 95 DF, p-value: <2e-16
# Look at anova table to get MSE
# 5-fold Cross Validation
cv5res=cv.lm(data=d, yf.lm,m=5)
## Analysis of Variance Table
##
## Response: y
## Df Sum Sq Mean Sq F value Pr(>F)
## x1 1 287754 287754 1540.8 < 2e-16 ***
## x2 1 4283247 4283247 22934.4 < 2e-16 ***
## x2s 1 86409 86409 462.7 < 2e-16 ***
## x1x2 1 5191 5191 27.8 8.4e-07 ***
## Residuals 95 17742 187
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = d, yf.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 20
## 1 12 14 20 29 32 38 40 52
## Predicted 579.1 601.0 414.2 91.1 324.9 254.21 373.22 192.38 433.03
## cvpred 578.5 599.3 414.7 91.1 325.6 253.84 372.11 192.94 431.86
## y 597.1 619.5 426.9 71.7 313.3 256.72 363.09 199.76 427.01
## CV residual 18.6 20.2 12.2 -19.4 -12.4 2.88 -9.01 6.82 -4.85
## 57 60 66 69 72 81 83 86 91 96
## Predicted 195.7 319.07 530.467 581.54 805.4 236.6 739.0 759.0 408.74 475
## cvpred 195.5 317.99 529.218 582.66 801.0 235.9 735.6 757.3 408.21 475
## y 212.7 327.93 529.994 581.19 811.4 256.4 758.1 751.1 401.70 460
## CV residual 17.2 9.94 0.777 -1.48 10.4 20.5 22.4 -6.2 -6.52 -16
## 98
## Predicted 504.03
## cvpred 503.24
## y 509.64
## CV residual 6.39
##
## Sum of squares = 3397 Mean square = 170 n = 20
##
## fold 2
## Observations in test set: 20
## 3 8 15 16 17 18 23 28 31 33
## Predicted 843 366.4 466.26 463.0 342.0 91.5 245.4 334.85 681.1 495.5
## cvpred 845 367.1 467.11 463.0 343.7 93.6 245.7 335.11 683.1 495.7
## y 835 343.5 461.94 481.6 316.8 72.3 260.8 338.47 661.8 475.0
## CV residual -10 -23.7 -5.17 18.6 -26.9 -21.3 15.1 3.37 -21.3 -20.7
## 39 42 45 48 58 59 62 63 90 100
## Predicted 539.3 -82.81 331.85 150.3 415.1 591.9 622.94 424.2 44.4 99.0
## cvpred 539.8 -79.35 332.62 153.3 415.8 592.3 623.26 424.2 46.2 105.1
## y 550.1 -77.58 329.41 133.2 400.0 603.5 628.19 442.6 28.0 76.4
## CV residual 10.3 1.77 -3.21 -20.2 -15.8 11.2 4.93 18.4 -18.2 -28.6
##
## Sum of squares = 5745 Mean square = 287 n = 20
##
## fold 3
## Observations in test set: 20
## 4 5 9 10 13 19 27 30 36 46
## Predicted 453.1 353.99 475.6 431.2 466.2 445.8 400.0 27.7 577 568.235
## cvpred 453.3 354.94 476.5 432.2 466.3 445.9 400.0 27.8 577 568.639
## y 442.1 357.37 493.0 445.9 453.9 458.3 421.1 45.5 592 568.814
## CV residual -11.2 2.43 16.5 13.7 -12.4 12.4 21.2 17.8 15 0.176
## 47 49 55 61 70 78 82 92 93
## Predicted -263.65 574.2 79.4 587.1 1.85 614.32 443.1 456.1 233.9
## cvpred -264.66 576.1 79.5 587.4 1.48 614.46 444.2 456.8 234.7
## y -260.17 556.8 59.9 565.9 -4.30 610.63 422.7 437.9 218.4
## CV residual 4.48 -19.3 -19.6 -21.5 -5.79 -3.83 -21.4 -18.9 -16.4
## 94
## Predicted 563.73
## cvpred 564.00
## y 565.86
## CV residual 1.86
##
## Sum of squares = 4265 Mean square = 213 n = 20
##
## fold 4
## Observations in test set: 20
## 7 25 26 35 43 54 56 67 68
## Predicted 702.16 323.144 653.23 551.1 421.7 103.36 592.02 367.9 358.3
## cvpred 702.05 322.906 653.00 550.9 421.5 102.41 591.86 367.6 357.8
## y 700.39 323.131 657.76 561.5 436.9 106.08 595.68 381.7 377.0
## CV residual -1.65 0.225 4.76 10.6 15.4 3.67 3.82 14.1 19.1
## 73 74 76 77 84 85 87 88 89 97
## Predicted 588.69 311.64 651.1 496.5 -84.90 170.2 571.7 527 743.26 481.4
## cvpred 588.57 311.15 650.9 496.3 -85.86 169.4 571.5 527 743.12 481.3
## y 580.28 307.71 640.3 508.1 -76.63 163.8 558.7 545 748.34 458.5
## CV residual -8.29 -3.44 -10.6 11.8 9.23 -5.6 -12.8 18 5.22 -22.8
## 99
## Predicted 399
## cvpred 399
## y 382
## CV residual -17
##
## Sum of squares = 2740 Mean square = 137 n = 20
##
## fold 5
## Observations in test set: 20
## 2 6 11 21 22 24 34 37 41 44
## Predicted 42.8 428.3 221.24 619.0 600.8 656.69 301.16 532 222.5 383.22
## cvpred 37.2 428.6 220.62 621.4 603.2 656.00 300.16 529 219.2 381.97
## y 56.1 418.4 228.55 592.6 596.1 651.69 293.24 550 241.1 386.91
## CV residual 18.9 -10.2 7.93 -28.9 -7.1 -4.31 -6.92 21 21.9 4.94
## 50 51 53 64 65 71 75 79 80
## Predicted 521.44 547.6 606.5 603.9 335.3 468.34 613.28 708.99 -36.2
## cvpred 522.36 547.5 605.7 603.0 334.4 466.35 609.21 701.99 -41.2
## y 519.61 536.6 621.3 615.8 348.0 470.91 617.29 710.44 -19.0
## CV residual -2.75 -10.9 15.6 12.8 13.6 4.56 8.08 8.46 22.2
## 95
## Predicted 210.344
## cvpred 209.240
## y 208.249
## CV residual -0.991
##
## Sum of squares = 3794 Mean square = 190 n = 20
##
## Overall (Sum over all 20 folds)
## ms
## 199
# Part g: Compare Models using F Tests
anova(ye.lm,yf.lm)
## Analysis of Variance Table
##
## Model 1: y ~ z1 + z2 + z2s + z1z2
## Model 2: y ~ x1 + x2 + x2s + x1x2
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 95 17742
## 2 95 17742 0 -1.24e-10
# Question 2
# Load alr3 library
library("alr3")
## Warning: package 'alr3' was built under R version 3.3.3
## Loading required package: car
## Warning: package 'car' was built under R version 3.3.3
##
## Attaching package: 'car'
## The following object is masked from 'package:DAAG':
##
## vif
##
## Attaching package: 'alr3'
## The following object is masked from 'package:DAAG':
##
## ais
# Read in and plot data
dat1=BGSall
# part a: Scatter plot matrix
plot(~WT9+HT9+ST9+LG9+Sex+Soma,data=dat1,pch=c(16,18)[as.factor(dat1$Sex)],col=c("red","blue")[as.factor(dat1$Sex)])

# part b: Fit model
modelb.lm=lm(Soma~factor(Sex),data=dat1)
summary(modelb.lm)
##
## Call:
## lm(formula = Soma ~ factor(Sex), data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.091 -0.779 -0.091 0.721 3.909
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.091 0.143 21.59 < 2e-16 ***
## factor(Sex)1 1.688 0.200 8.46 4.1e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.16 on 134 degrees of freedom
## Multiple R-squared: 0.348, Adjusted R-squared: 0.343
## F-statistic: 71.5 on 1 and 134 DF, p-value: 4.12e-14
anova(modelb.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## factor(Sex) 1 96.8 96.8 71.5 4.1e-14 ***
## Residuals 134 181.3 1.4
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model 1 - Coincident Regressions
modelb1.lm=lm(Soma~WT9*factor(Sex)+HT9*factor(Sex)+ST9*factor(Sex)+LG9*factor(Sex),data=dat1)
summary(modelb1.lm)
##
## Call:
## lm(formula = Soma ~ WT9 * factor(Sex) + HT9 * factor(Sex) + ST9 *
## factor(Sex) + LG9 * factor(Sex), data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.274 -0.581 -0.021 0.446 3.406
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.1652 4.8484 2.10 0.0380 *
## WT9 0.1071 0.0651 1.64 0.1026
## factor(Sex)1 -3.3342 6.7762 -0.49 0.6235
## HT9 -0.0833 0.0315 -2.64 0.0092 **
## ST9 -0.0452 0.0109 -4.17 5.6e-05 ***
## LG9 0.1447 0.1537 0.94 0.3482
## WT9:factor(Sex)1 0.0139 0.0867 0.16 0.8728
## factor(Sex)1:HT9 0.0419 0.0474 0.88 0.3790
## factor(Sex)1:ST9 0.0377 0.0147 2.57 0.0114 *
## factor(Sex)1:LG9 -0.1383 0.1930 -0.72 0.4750
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.985 on 126 degrees of freedom
## Multiple R-squared: 0.56, Adjusted R-squared: 0.528
## F-statistic: 17.8 on 9 and 126 DF, p-value: <2e-16
anova(modelb1.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT9 1 22.3 22.3 22.98 4.5e-06 ***
## factor(Sex) 1 96.8 96.8 99.71 < 2e-16 ***
## HT9 1 14.5 14.5 14.97 0.00017 ***
## ST9 1 9.9 9.9 10.16 0.00181 **
## LG9 1 0.2 0.2 0.16 0.68887
## WT9:factor(Sex) 1 1.6 1.6 1.67 0.19892
## factor(Sex):HT9 1 3.9 3.9 4.00 0.04773 *
## factor(Sex):ST9 1 5.9 5.9 6.12 0.01470 *
## factor(Sex):LG9 1 0.5 0.5 0.51 0.47498
## Residuals 126 122.4 1.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model 2 - Parallel
modelb2.lm=lm(Soma~WT9+HT9+ST9+LG9+factor(Sex),data=dat1)
summary(modelb2.lm)
##
## Call:
## lm(formula = Soma ~ WT9 + HT9 + ST9 + LG9 + factor(Sex), data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.993 -0.661 0.040 0.493 3.574
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.59474 3.41174 2.23 0.0277 *
## WT9 0.11960 0.04353 2.75 0.0069 **
## HT9 -0.05686 0.02398 -2.37 0.0192 *
## ST9 -0.02296 0.00738 -3.11 0.0023 **
## LG9 0.03714 0.09546 0.39 0.6978
## factor(Sex)1 1.43848 0.18772 7.66 3.7e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.02 on 130 degrees of freedom
## Multiple R-squared: 0.517, Adjusted R-squared: 0.498
## F-statistic: 27.8 on 5 and 130 DF, p-value: <2e-16
anova(modelb2.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT9 1 22.3 22.3 21.60 8.1e-06 ***
## HT9 1 22.4 22.4 21.73 7.7e-06 ***
## ST9 1 34.2 34.2 33.13 5.9e-08 ***
## LG9 1 4.0 4.0 3.92 0.05 *
## factor(Sex) 1 60.7 60.7 58.72 3.7e-12 ***
## Residuals 130 134.3 1.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model 3 - Common Intercept
modelb3.lm=lm(Soma~WT9+WT9:factor(Sex)+HT9+HT9:factor(Sex)+ST9+ST9:factor(Sex)+LG9+LG9:factor(Sex),data=dat1)
summary(modelb3.lm)
##
## Call:
## lm(formula = Soma ~ WT9 + WT9:factor(Sex) + HT9 + HT9:factor(Sex) +
## ST9 + ST9:factor(Sex) + LG9 + LG9:factor(Sex), data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.302 -0.604 -0.023 0.439 3.459
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.4583 3.3770 2.50 0.0135 *
## WT9 0.0903 0.0553 1.63 0.1048
## HT9 -0.0736 0.0245 -3.00 0.0032 **
## ST9 -0.0463 0.0106 -4.36 2.7e-05 ***
## LG9 0.1808 0.1347 1.34 0.1819
## WT9:factor(Sex)1 0.0449 0.0593 0.76 0.4501
## factor(Sex)1:HT9 0.0210 0.0213 0.99 0.3256
## factor(Sex)1:ST9 0.0401 0.0139 2.89 0.0045 **
## factor(Sex)1:LG9 -0.1977 0.1501 -1.32 0.1902
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.983 on 127 degrees of freedom
## Multiple R-squared: 0.559, Adjusted R-squared: 0.531
## F-statistic: 20.1 on 8 and 127 DF, p-value: <2e-16
anova(modelb3.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT9 1 22.3 22.3 23.12 4.2e-06 ***
## HT9 1 22.4 22.4 23.25 4.0e-06 ***
## ST9 1 34.2 34.2 35.46 2.4e-08 ***
## LG9 1 4.0 4.0 4.19 0.0427 *
## WT9:factor(Sex) 1 62.2 62.2 64.43 5.8e-13 ***
## factor(Sex):HT9 1 0.4 0.4 0.43 0.5148
## factor(Sex):ST9 1 8.1 8.1 8.38 0.0045 **
## factor(Sex):LG9 1 1.7 1.7 1.73 0.1902
## Residuals 127 122.6 1.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model 4 - No Restrcition
modelb4.lm=lm(Soma~WT9+HT9+ST9+LG9,data=dat1)
summary(modelb4.lm)
##
## Call:
## lm(formula = Soma ~ WT9 + HT9 + ST9 + LG9, data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.9427 -0.8608 0.0352 0.9020 2.9792
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.18495 4.07754 1.27 0.21
## WT9 0.08005 0.05188 1.54 0.13
## HT9 -0.04580 0.02874 -1.59 0.11
## ST9 -0.04139 0.00837 -4.95 2.3e-06 ***
## LG9 0.18502 0.11221 1.65 0.10
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.22 on 131 degrees of freedom
## Multiple R-squared: 0.299, Adjusted R-squared: 0.277
## F-statistic: 13.9 on 4 and 131 DF, p-value: 1.66e-09
anova(modelb4.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT9 1 22.3 22.3 14.99 0.00017 ***
## HT9 1 22.4 22.4 15.08 0.00016 ***
## ST9 1 34.2 34.2 23.00 4.3e-06 ***
## LG9 1 4.0 4.0 2.72 0.10157
## Residuals 131 195.0 1.5
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Compare Models using F Tests
anova(modelb2.lm,modelb1.lm)
## Analysis of Variance Table
##
## Model 1: Soma ~ WT9 + HT9 + ST9 + LG9 + factor(Sex)
## Model 2: Soma ~ WT9 * factor(Sex) + HT9 * factor(Sex) + ST9 * factor(Sex) +
## LG9 * factor(Sex)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 130 134
## 2 126 122 4 11.9 3.07 0.019 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(modelb3.lm,modelb1.lm)
## Analysis of Variance Table
##
## Model 1: Soma ~ WT9 + WT9:factor(Sex) + HT9 + HT9:factor(Sex) + ST9 +
## ST9:factor(Sex) + LG9 + LG9:factor(Sex)
## Model 2: Soma ~ WT9 * factor(Sex) + HT9 * factor(Sex) + ST9 * factor(Sex) +
## LG9 * factor(Sex)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 127 123
## 2 126 122 1 0.235 0.24 0.62
anova(modelb4.lm,modelb1.lm)
## Analysis of Variance Table
##
## Model 1: Soma ~ WT9 + HT9 + ST9 + LG9
## Model 2: Soma ~ WT9 * factor(Sex) + HT9 * factor(Sex) + ST9 * factor(Sex) +
## LG9 * factor(Sex)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 131 195
## 2 126 122 5 72.6 14.9 1.6e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(modelb.lm,modelb1.lm)
## Analysis of Variance Table
##
## Model 1: Soma ~ factor(Sex)
## Model 2: Soma ~ WT9 * factor(Sex) + HT9 * factor(Sex) + ST9 * factor(Sex) +
## LG9 * factor(Sex)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 134 181
## 2 126 122 8 58.9 7.58 3.1e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Cross Validation
cv5res1=cv.lm(data=dat1,modelb1.lm,m=5)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT9 1 22.3 22.3 22.98 4.5e-06 ***
## factor(Sex) 1 96.8 96.8 99.71 < 2e-16 ***
## HT9 1 14.5 14.5 14.97 0.00017 ***
## ST9 1 9.9 9.9 10.16 0.00181 **
## LG9 1 0.2 0.2 0.16 0.68887
## WT9:factor(Sex) 1 1.6 1.6 1.67 0.19892
## factor(Sex):HT9 1 3.9 3.9 4.00 0.04773 *
## factor(Sex):ST9 1 5.9 5.9 6.12 0.01470 *
## factor(Sex):LG9 1 0.5 0.5 0.51 0.47498
## Residuals 126 122.4 1.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = dat1, modelb1.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 27
## 10 12 17 25 34 39 43 48 51
## Predicted 3.528 2.455 3.035 2.152 3.927 3.42 3.0475 2.67 2.258
## cvpred 3.833 2.409 2.841 2.157 3.977 3.28 2.9777 2.51 2.205
## Soma 3.000 3.000 2.500 2.000 3.000 6.00 3.0000 4.00 2.000
## CV residual -0.833 0.591 -0.341 -0.157 -0.977 2.72 0.0223 1.49 -0.205
## 63 66 68 70 74 77 79 81 85
## Predicted 2.77 3.131 4.289 5.6568 4.294 4.68 5.335 4.325 5.141
## cvpred 2.93 3.101 4.278 5.5662 4.319 4.71 5.321 4.395 5.112
## Soma 1.00 3.000 4.000 5.5000 4.000 5.00 5.500 5.000 5.500
## CV residual -1.93 -0.101 -0.278 -0.0662 -0.319 0.29 0.179 0.605 0.388
## 86 97 100 103 111 119 123 124 135
## Predicted 5.076 4.92 5.133 4.507 4.295 5.095 4.49 4.241 5.755
## cvpred 5.094 4.94 5.224 4.601 4.303 5.092 4.62 4.213 5.808
## Soma 4.500 6.00 5.000 5.000 4.000 5.500 3.00 4.500 5.500
## CV residual -0.594 1.06 -0.224 0.399 -0.303 0.408 -1.62 0.287 -0.308
##
## Sum of squares = 21.1 Mean square = 0.78 n = 27
##
## fold 2
## Observations in test set: 28
## 3 9 16 23 35 36 42 52 56 58
## Predicted 2.97 3.116 2.87 2.78 4.28 3.712 3.317 3.73 2.545 3.66
## cvpred 2.98 3.145 2.55 2.76 4.50 3.798 3.488 3.96 2.456 3.89
## Soma 6.00 4.000 4.00 4.00 3.50 4.000 3.000 2.00 1.500 2.00
## CV residual 3.02 0.855 1.45 1.24 -1.00 0.202 -0.488 -1.96 -0.956 -1.89
## 65 67 72 80 88 91 95 98 101
## Predicted 3.323 4.8579 3.873 4.211 4.598 4.353 4.887 6.42 4.697
## cvpred 3.263 4.9747 3.905 4.122 4.698 4.419 4.911 6.79 4.727
## Soma 3.000 5.0000 3.000 4.000 5.000 4.000 5.000 4.50 5.000
## CV residual -0.263 0.0253 -0.905 -0.122 0.302 -0.419 0.089 -2.29 0.273
## 102 106 108 121 125 127 132 133 136
## Predicted 4.032 4.285 5.737 4.803 4.792 6.025 4.22 4.306 5.776
## cvpred 3.956 4.385 5.923 4.881 4.812 6.371 4.17 4.247 5.916
## Soma 4.000 4.000 6.500 4.000 5.000 6.500 4.00 4.500 5.500
## CV residual 0.044 -0.385 0.577 -0.881 0.188 0.129 -0.17 0.253 -0.416
##
## Sum of squares = 31.2 Mean square = 1.12 n = 28
##
## fold 3
## Observations in test set: 27
## 8 14 15 22 38 40 45 47 50 53
## Predicted 3.091 3.146 3.26 3.71 2.98 2.70 3.506 3.18 3.64 2.30
## cvpred 3.055 3.939 3.45 4.52 3.03 3.98 3.025 3.54 3.37 2.77
## Soma 4.000 3.000 2.50 3.00 2.00 1.50 3.500 2.00 4.00 1.00
## CV residual 0.945 -0.939 -0.95 -1.52 -1.03 -2.48 0.475 -1.54 0.63 -1.77
## 54 55 57 60 62 64 75 76 82 84
## Predicted 3.635 2.22 2.72 5.40 3.308 4.10 4.564 5.49299 5.35 4.132
## cvpred 3.722 3.28 2.66 8.79 3.566 4.52 4.584 5.50479 5.25 4.145
## Soma 4.000 1.50 1.50 4.00 4.000 6.00 5.000 5.50000 6.50 3.500
## CV residual 0.278 -1.78 -1.16 -4.79 0.434 1.48 0.416 -0.00479 1.25 -0.645
## 90 96 99 117 120 122 129
## Predicted 4.310 4.47 4.478 4.97570 4.913 4.821 4.107
## cvpred 4.366 4.42 4.469 5.00855 4.861 4.842 4.084
## Soma 4.000 5.00 5.000 5.00000 5.500 4.000 3.500
## CV residual -0.366 0.58 0.531 -0.00855 0.639 -0.842 -0.584
##
## Sum of squares = 52.6 Mean square = 1.95 n = 27
##
## fold 4
## Observations in test set: 27
## 2 5 6 7 13 18 19 20 21 30 33
## Predicted 1.92 2.70 2.404 4.04 3.25 2.99 3.59 3.337 1.446 3.06 2.310
## cvpred 1.95 2.57 2.341 3.80 3.15 2.88 3.44 3.218 1.518 2.97 2.252
## Soma 4.00 1.50 3.000 6.00 4.00 2.00 7.00 4.000 1.000 1.50 3.000
## CV residual 2.05 -1.07 0.659 2.20 0.85 -0.88 3.56 0.782 -0.518 -1.47 0.748
## 37 49 73 92 94 104 105 107 110
## Predicted 1.773 2.48 4.49 5.280 4.4993 4.780 4.583 4.5101 4.59
## cvpred 1.779 2.49 4.49 5.256 4.5384 4.785 4.593 4.5217 4.59
## Soma 2.000 2.00 5.00 5.000 4.5000 4.000 4.500 4.5000 3.50
## CV residual 0.221 -0.49 0.51 -0.256 -0.0384 -0.785 -0.093 -0.0217 -1.09
## 114 115 116 118 126 128 134
## Predicted 4.680 3.97401 4.293 4.714 4.129 4.404 5.99
## cvpred 4.691 4.00407 4.237 4.653 4.119 4.418 5.98
## Soma 4.000 4.00000 5.000 5.000 4.000 5.000 7.00
## CV residual -0.691 -0.00407 0.763 0.347 -0.119 0.582 1.02
##
## Sum of squares = 33.4 Mean square = 1.24 n = 27
##
## fold 5
## Observations in test set: 27
## 1 4 11 24 26 27 28 29 31
## Predicted 4.22 3.22 2.619 2.9237 2.82 2.52 2.594 3.565 3.77
## cvpred 4.28 3.14 2.619 3.0984 3.00 2.44 2.821 3.994 3.94
## Soma 7.00 2.00 3.000 3.0000 1.00 4.00 2.000 3.000 1.50
## CV residual 2.72 -1.14 0.381 -0.0984 -2.00 1.56 -0.821 -0.994 -2.44
## 32 41 44 46 59 61 69 71 78
## Predicted 6.0947 2.2308 3.20 2.397 2.641 2.283 5.759 4.359 4.778
## cvpred 6.0686 2.0597 3.03 2.593 2.544 2.432 5.828 4.373 4.719
## Soma 6.0000 2.0000 3.50 2.000 3.000 3.000 5.500 4.500 5.000
## CV residual -0.0686 -0.0597 0.47 -0.593 0.456 0.568 -0.328 0.127 0.281
## 83 87 89 93 109 112 113 130 131
## Predicted 4.5942 4.74 4.452 5.47 5.107 4.761 5.22 5.082 4.56
## cvpred 4.5403 4.62 4.376 5.61 5.031 4.789 5.11 5.032 4.51
## Soma 4.5000 6.00 4.500 4.50 5.500 5.000 4.50 5.500 5.00
## CV residual -0.0403 1.38 0.124 -1.11 0.469 0.211 -0.61 0.468 0.49
##
## Sum of squares = 28.5 Mean square = 1.05 n = 27
##
## Overall (Sum over all 27 folds)
## ms
## 1.23
cv5res1=cv.lm(data=dat1,modelb2.lm,m=5)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT9 1 22.3 22.3 21.60 8.1e-06 ***
## HT9 1 22.4 22.4 21.73 7.7e-06 ***
## ST9 1 34.2 34.2 33.13 5.9e-08 ***
## LG9 1 4.0 4.0 3.92 0.05 *
## factor(Sex) 1 60.7 60.7 58.72 3.7e-12 ***
## Residuals 130 134.3 1.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = dat1, modelb2.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 27
## 10 12 17 25 34 39 43 48 51 63
## Predicted 3.526 2.49 3.17 2.400 3.159 3.29 2.9496 2.89 2.538 2.85
## cvpred 3.776 2.48 2.98 2.406 3.232 3.18 2.9042 2.71 2.506 3.01
## Soma 3.000 3.00 2.50 2.000 3.000 6.00 3.0000 4.00 2.000 1.00
## CV residual -0.776 0.52 -0.48 -0.406 -0.232 2.82 0.0958 1.29 -0.506 -2.01
## 66 68 70 74 77 79 81 85 86
## Predicted 3.1312 4.201 5.449 4.584 4.664 5.152 4.643 5.3174 5.061
## cvpred 3.0835 4.214 5.315 4.638 4.789 5.213 4.852 5.4063 5.174
## Soma 3.0000 4.000 5.500 4.000 5.000 5.500 5.000 5.5000 4.500
## CV residual -0.0835 -0.214 0.185 -0.638 0.211 0.287 0.148 0.0937 -0.674
## 97 100 103 111 119 123 124 135
## Predicted 4.99 5.338 5.155 4.322 4.742 4.91 3.923 5.801
## cvpred 5.08 5.531 5.345 4.363 4.781 5.26 3.846 5.968
## Soma 6.00 5.000 5.000 4.000 5.500 3.00 4.500 5.500
## CV residual 0.92 -0.531 -0.345 -0.363 0.719 -2.26 0.654 -0.468
##
## Sum of squares = 24 Mean square = 0.89 n = 27
##
## fold 2
## Observations in test set: 28
## 3 9 16 23 35 36 42 52 56 58
## Predicted 2.95 3.039 3.402 2.87 3.743 3.348 3.006 3.25 2.66 3.21
## cvpred 2.89 3.041 3.191 2.82 3.828 3.343 3.092 3.37 2.57 3.31
## Soma 6.00 4.000 4.000 4.00 3.500 4.000 3.000 2.00 1.50 2.00
## CV residual 3.11 0.959 0.809 1.18 -0.328 0.657 -0.092 -1.37 -1.07 -1.31
## 65 67 72 80 88 91 95 98 101
## Predicted 3.303 4.692 3.826 4.571 4.916 4.628 5.255 6.31 4.975
## cvpred 3.179 4.834 3.956 4.767 5.255 4.945 5.523 6.50 5.218
## Soma 3.000 5.000 3.000 4.000 5.000 4.000 5.000 4.50 5.000
## CV residual -0.179 0.166 -0.956 -0.767 -0.255 -0.945 -0.523 -2.00 -0.218
## 102 106 108 121 125 127 132 133 136
## Predicted 3.790 4.66 5.896 5.28 4.889 6.471 4.0782 4.3881 5.611
## cvpred 3.733 5.03 6.138 5.66 5.063 6.863 4.0972 4.4807 5.691
## Soma 4.000 4.00 6.500 4.00 5.000 6.500 4.0000 4.5000 5.500
## CV residual 0.267 -1.03 0.362 -1.66 -0.063 -0.363 -0.0972 0.0193 -0.191
##
## Sum of squares = 28.9 Mean square = 1.03 n = 28
##
## fold 3
## Observations in test set: 27
## 8 14 15 22 38 40 45 47 50 53
## Predicted 3.124 3.219 3.273 3.403 2.90 3.02 3.211 3.01 3.298 2.73
## cvpred 3.093 3.739 3.404 3.949 3.02 3.74 2.984 3.32 3.263 3.01
## Soma 4.000 3.000 2.500 3.000 2.00 1.50 3.500 2.00 4.000 1.00
## CV residual 0.907 -0.739 -0.904 -0.949 -1.02 -2.24 0.516 -1.32 0.737 -2.01
## 54 55 57 60 62 64 75 76 82 84
## Predicted 3.312 3.00 2.64 5.92 3.037 4.03 4.358 5.040 5.44 4.277
## cvpred 3.425 3.47 2.70 7.41 3.306 4.17 4.622 4.924 5.43 4.441
## Soma 4.000 1.50 1.50 4.00 4.000 6.00 5.000 5.500 6.50 3.500
## CV residual 0.575 -1.97 -1.20 -3.41 0.694 1.83 0.378 0.576 1.07 -0.941
## 90 96 99 117 120 122 129
## Predicted 3.943 4.624 4.629 4.97 5.056 4.620 4.22
## cvpred 3.737 4.349 4.468 4.83 4.975 4.601 3.79
## Soma 4.000 5.000 5.000 5.00 5.500 4.000 3.50
## CV residual 0.263 0.651 0.532 0.17 0.525 -0.601 -0.29
##
## Sum of squares = 40.8 Mean square = 1.51 n = 27
##
## fold 4
## Observations in test set: 27
## 2 5 6 7 13 18 19 20 21 30 33
## Predicted 2.39 2.65 2.650 3.35 3.110 3.03 3.43 3.214 2.26 2.96 2.512
## cvpred 2.43 2.55 2.578 3.21 3.071 2.92 3.30 3.136 2.28 2.93 2.472
## Soma 4.00 1.50 3.000 6.00 4.000 2.00 7.00 4.000 1.00 1.50 3.000
## CV residual 1.57 -1.05 0.422 2.79 0.929 -0.92 3.70 0.864 -1.28 -1.43 0.528
## 37 49 73 92 94 104 105 107
## Predicted 2.37 2.769 4.361 5.40 4.42541 4.782 4.6098 4.5343
## cvpred 2.32 2.806 4.352 5.33 4.50505 4.779 4.5991 4.5223
## Soma 2.00 2.000 5.000 5.00 4.50000 4.000 4.5000 4.5000
## CV residual -0.32 -0.806 0.648 -0.33 -0.00505 -0.779 -0.0991 -0.0223
## 110 114 115 116 118 126 128 134
## Predicted 4.481 4.842 3.9138 3.44 4.309 3.869 4.623 6.324
## cvpred 4.493 4.801 3.9375 3.47 4.238 3.852 4.562 6.286
## Soma 3.500 4.000 4.0000 5.00 5.000 4.000 5.000 7.000
## CV residual -0.993 -0.801 0.0625 1.53 0.762 0.148 0.438 0.714
##
## Sum of squares = 38.8 Mean square = 1.44 n = 27
##
## fold 5
## Observations in test set: 27
## 1 4 11 24 26 27 28 29 31 32
## Predicted 4.11 3.30 2.655 2.9240 2.92 2.70 2.739 3.29 3.49 5.251
## cvpred 4.08 3.25 2.701 3.0295 3.03 2.64 2.898 3.55 3.55 5.108
## Soma 7.00 2.00 3.000 3.0000 1.00 4.00 2.000 3.00 1.50 6.000
## CV residual 2.92 -1.25 0.299 -0.0295 -2.03 1.36 -0.898 -0.55 -2.05 0.892
## 41 44 46 59 61 69 71 78 83 87
## Predicted 2.593 3.11 2.75 2.646 2.546 5.096 3.994 4.646 4.477 4.58
## cvpred 2.524 3.02 2.90 2.616 2.682 4.791 3.962 4.455 4.291 4.43
## Soma 2.000 3.50 2.00 3.000 3.000 5.500 4.500 5.000 4.500 6.00
## CV residual -0.524 0.48 -0.90 0.384 0.318 0.709 0.538 0.545 0.209 1.57
## 89 93 109 112 113 130 131
## Predicted 4.392 5.264 4.991 4.563 5.28 5.05 4.587
## cvpred 4.308 5.252 4.812 4.587 5.10 4.83 4.547
## Soma 4.500 4.500 5.500 5.000 4.50 5.50 5.000
## CV residual 0.192 -0.752 0.688 0.413 -0.60 0.67 0.453
##
## Sum of squares = 29.6 Mean square = 1.1 n = 27
##
## Overall (Sum over all 27 folds)
## ms
## 1.19
cv5res1=cv.lm(data=dat1,modelb3.lm,m=5)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT9 1 22.3 22.3 23.12 4.2e-06 ***
## HT9 1 22.4 22.4 23.25 4.0e-06 ***
## ST9 1 34.2 34.2 35.46 2.4e-08 ***
## LG9 1 4.0 4.0 4.19 0.0427 *
## WT9:factor(Sex) 1 62.2 62.2 64.43 5.8e-13 ***
## factor(Sex):HT9 1 0.4 0.4 0.43 0.5148
## factor(Sex):ST9 1 8.1 8.1 8.38 0.0045 **
## factor(Sex):LG9 1 1.7 1.7 1.73 0.1902
## Residuals 127 122.6 1.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = dat1, modelb3.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 27
## 10 12 17 25 34 39 43 48 51
## Predicted 3.578 2.468 3.004 2.162 3.824 3.42 3.0308 2.62 2.295
## cvpred 3.861 2.414 2.824 2.161 3.917 3.27 2.9672 2.48 2.225
## Soma 3.000 3.000 2.500 2.000 3.000 6.00 3.0000 4.00 2.000
## CV residual -0.861 0.586 -0.324 -0.161 -0.917 2.73 0.0328 1.52 -0.225
## 63 66 68 70 74 77 79 81 85
## Predicted 2.85 3.0913 4.267 5.694 4.313 4.632 5.291 4.267 5.066
## cvpred 2.97 3.0789 4.262 5.584 4.323 4.679 5.291 4.353 5.056
## Soma 1.00 3.0000 4.000 5.500 4.000 5.000 5.500 5.000 5.500
## CV residual -1.97 -0.0789 -0.262 -0.084 -0.323 0.321 0.209 0.647 0.444
## 86 97 100 103 111 119 123 124 135
## Predicted 5.034 4.90 5.141 4.532 4.283 5.070 4.41 4.26 5.741
## cvpred 5.063 4.91 5.223 4.604 4.291 5.078 4.57 4.23 5.794
## Soma 4.500 6.00 5.000 5.000 4.000 5.500 3.00 4.50 5.500
## CV residual -0.563 1.09 -0.223 0.396 -0.291 0.422 -1.57 0.27 -0.294
##
## Sum of squares = 21.3 Mean square = 0.79 n = 27
##
## fold 2
## Observations in test set: 28
## 3 9 16 23 35 36 42 52 56 58
## Predicted 2.97 3.117 2.92 2.77 4.259 3.760 3.289 3.69 2.593 3.62
## cvpred 2.98 3.148 2.59 2.75 4.482 3.834 3.467 3.94 2.496 3.86
## Soma 6.00 4.000 4.00 4.00 3.500 4.000 3.000 2.00 1.500 2.00
## CV residual 3.02 0.852 1.41 1.25 -0.982 0.166 -0.467 -1.94 -0.996 -1.86
## 65 67 72 80 88 91 95 98 101
## Predicted 3.371 4.8950 3.902 4.185 4.659 4.409 4.893 6.49 4.710
## cvpred 3.298 5.0197 3.924 4.109 4.777 4.488 4.943 6.89 4.759
## Soma 3.000 5.0000 3.000 4.000 5.000 4.000 5.000 4.50 5.000
## CV residual -0.298 -0.0197 -0.924 -0.109 0.223 -0.488 0.057 -2.39 0.241
## 102 106 108 121 125 127 132 133 136
## Predicted 3.986 4.361 5.770 4.850 4.79 6.11422 4.192 4.276 5.773
## cvpred 3.898 4.475 5.987 4.956 4.83 6.49459 4.138 4.223 5.936
## Soma 4.000 4.000 6.500 4.000 5.00 6.50000 4.000 4.500 5.500
## CV residual 0.102 -0.475 0.513 -0.956 0.17 0.00541 -0.138 0.277 -0.436
##
## Sum of squares = 31.5 Mean square = 1.13 n = 28
##
## fold 3
## Observations in test set: 27
## 8 14 15 22 38 40 45 47 50 53
## Predicted 3.07 3.176 3.28 3.65 2.97 2.64 3.50 3.14 3.699 2.31
## cvpred 2.97 3.956 3.51 4.22 3.01 3.60 3.04 3.39 3.624 2.75
## Soma 4.00 3.000 2.50 3.00 2.00 1.50 3.50 2.00 4.000 1.00
## CV residual 1.03 -0.956 -1.01 -1.22 -1.01 -2.10 0.46 -1.39 0.376 -1.75
## 54 55 57 60 62 64 75 76 82 84
## Predicted 3.600 2.21 2.67 5.33 3.281 4.10 4.599 5.397 5.38 4.198
## cvpred 3.581 3.05 2.51 7.99 3.457 4.41 4.728 5.056 5.34 4.444
## Soma 4.000 1.50 1.50 4.00 4.000 6.00 5.000 5.500 6.50 3.500
## CV residual 0.419 -1.55 -1.01 -3.99 0.543 1.59 0.272 0.444 1.16 -0.944
## 90 96 99 117 120 122 129
## Predicted 4.2443 4.476 4.479 4.915 4.928 4.790 4.09
## cvpred 4.0706 4.426 4.475 4.765 4.912 4.698 3.99
## Soma 4.0000 5.000 5.000 5.000 5.500 4.000 3.50
## CV residual -0.0706 0.574 0.525 0.235 0.588 -0.698 -0.49
##
## Sum of squares = 41.9 Mean square = 1.55 n = 27
##
## fold 4
## Observations in test set: 27
## 2 5 6 7 13 18 19 20 21 30
## Predicted 1.95 2.64 2.397 4.05 3.287 2.971 3.54 3.357 1.456 3.08
## cvpred 1.99 2.52 2.337 3.80 3.179 2.863 3.39 3.234 1.534 2.99
## Soma 4.00 1.50 3.000 6.00 4.000 2.000 7.00 4.000 1.000 1.50
## CV residual 2.01 -1.02 0.663 2.20 0.821 -0.863 3.61 0.766 -0.534 -1.49
## 33 37 49 73 92 94 104 105 107
## Predicted 2.286 1.774 2.568 4.484 5.276 4.4749 4.757 4.595 4.5159
## cvpred 2.238 1.782 2.564 4.484 5.248 4.5251 4.768 4.603 4.5273
## Soma 3.000 2.000 2.000 5.000 5.000 4.5000 4.000 4.500 4.5000
## CV residual 0.762 0.218 -0.564 0.516 -0.248 -0.0251 -0.768 -0.103 -0.0273
## 110 114 115 116 118 126 128 134
## Predicted 4.56 4.671 4.039 4.268 4.655 4.158 4.461 5.96
## cvpred 4.58 4.684 4.058 4.217 4.603 4.141 4.462 5.95
## Soma 3.50 4.000 4.000 5.000 5.000 4.000 5.000 7.00
## CV residual -1.08 -0.684 -0.058 0.783 0.397 -0.141 0.538 1.05
##
## Sum of squares = 33.6 Mean square = 1.24 n = 27
##
## fold 5
## Observations in test set: 27
## 1 4 11 24 26 27 28 29 31 32
## Predicted 4.23 3.19 2.607 2.97 2.87 2.49 2.657 3.671 3.80 6.0495
## cvpred 4.27 3.16 2.624 3.07 2.97 2.46 2.775 3.914 3.92 6.0981
## Soma 7.00 2.00 3.000 3.00 1.00 4.00 2.000 3.000 1.50 6.0000
## CV residual 2.73 -1.16 0.376 -0.07 -1.97 1.54 -0.775 -0.914 -2.42 -0.0981
## 41 44 46 59 61 69 71 78 83
## Predicted 2.1834 3.134 2.460 2.599 2.326 5.832 4.357 4.815 4.6400
## cvpred 2.0917 3.074 2.543 2.575 2.397 5.777 4.369 4.695 4.5126
## Soma 2.0000 3.500 2.000 3.000 3.000 5.500 4.500 5.000 4.5000
## CV residual -0.0917 0.426 -0.543 0.425 0.603 -0.277 0.131 0.305 -0.0126
## 87 89 93 109 112 113 130 131
## Predicted 4.73 4.450 5.47 5.12 4.730 5.218 5.129 4.549
## cvpred 4.62 4.375 5.60 5.02 4.802 5.105 5.003 4.516
## Soma 6.00 4.500 4.50 5.50 5.000 4.500 5.500 5.000
## CV residual 1.38 0.125 -1.10 0.48 0.198 -0.605 0.497 0.484
##
## Sum of squares = 27.9 Mean square = 1.04 n = 27
##
## Overall (Sum over all 27 folds)
## ms
## 1.15
cv5res1=cv.lm(data=dat1,modelb4.lm,m=5)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT9 1 22.3 22.3 14.99 0.00017 ***
## HT9 1 22.4 22.4 15.08 0.00016 ***
## ST9 1 34.2 34.2 23.00 4.3e-06 ***
## LG9 1 4.0 4.0 2.72 0.10157
## Residuals 131 195.0 1.5
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = dat1, modelb4.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 27
## 10 12 17 25 34 39 43 48 51 63
## Predicted 4.39 3.094 3.622 2.881 3.98 3.98 3.580 3.222 3.07 3.65
## cvpred 4.55 3.105 3.472 2.917 4.12 3.87 3.555 3.119 3.04 3.74
## Soma 3.00 3.000 2.500 2.000 3.00 6.00 3.000 4.000 2.00 1.00
## CV residual -1.55 -0.105 -0.972 -0.917 -1.12 2.13 -0.555 0.881 -1.04 -2.74
## 66 68 70 74 77 79 81 85 86 97
## Predicted 3.669 3.524 4.762 4.091 4.186 4.673 4.451 5.336 4.664 4.58
## cvpred 3.654 3.537 4.599 4.156 4.252 4.639 4.578 5.256 4.689 4.61
## Soma 3.000 4.000 5.500 4.000 5.000 5.500 5.000 5.500 4.500 6.00
## CV residual -0.654 0.463 0.901 -0.156 0.748 0.861 0.422 0.244 -0.189 1.39
## 100 103 111 119 123 124 135
## Predicted 4.8784 4.968 3.704 3.94 4.87 2.82 5.4297
## cvpred 5.0301 5.129 3.745 3.95 5.10 2.83 5.4943
## Soma 5.0000 5.000 4.000 5.50 3.00 4.50 5.5000
## CV residual -0.0301 -0.129 0.255 1.55 -2.10 1.67 0.0057
##
## Sum of squares = 34.3 Mean square = 1.27 n = 27
##
## fold 2
## Observations in test set: 28
## 3 9 16 23 35 36 42 52 56 58
## Predicted 3.62 3.704 3.887 3.426 4.71 4.328 3.731 4.09 3.29 4.03
## cvpred 3.62 3.731 3.777 3.426 4.83 4.366 3.818 4.20 3.25 4.14
## Soma 6.00 4.000 4.000 4.000 3.50 4.000 3.000 2.00 1.50 2.00
## CV residual 2.38 0.269 0.223 0.574 -1.33 -0.366 -0.818 -2.20 -1.75 -2.14
## 65 67 72 80 88 91 95 98 101 102
## Predicted 4.12 3.87 2.875 4.31 4.415 4.061 5.05 5.65 4.609 2.94
## cvpred 4.09 3.90 2.913 4.41 4.585 4.213 5.19 5.74 4.732 2.87
## Soma 3.00 5.00 3.000 4.00 5.000 4.000 5.00 4.50 5.000 4.00
## CV residual -1.09 1.10 0.087 -0.41 0.415 -0.213 -0.19 -1.24 0.268 1.13
## 106 108 121 125 127 132 133 136
## Predicted 4.08 5.544 5.04 4.435 6.160 3.338 3.877 5.100
## cvpred 4.27 5.668 5.24 4.507 6.395 3.314 3.909 5.115
## Soma 4.00 6.500 4.00 5.000 6.500 4.000 4.500 5.500
## CV residual -0.27 0.832 -1.24 0.493 0.105 0.686 0.591 0.385
##
## Sum of squares = 30.4 Mean square = 1.09 n = 28
##
## fold 3
## Observations in test set: 27
## 8 14 15 22 38 40 45 47 50 53
## Predicted 3.744 3.85 4.00 4.02 3.55 3.25 4.058 3.62 4.31 3.13
## cvpred 3.647 4.50 4.11 4.75 3.66 4.21 3.697 4.00 4.19 3.44
## Soma 4.000 3.00 2.50 3.00 2.00 1.50 3.500 2.00 4.00 1.00
## CV residual 0.353 -1.50 -1.61 -1.75 -1.66 -2.71 -0.197 -2.00 -0.19 -2.44
## 54 55 57 60 62 64 75 76 82 84
## Predicted 4.060 3.15 3.16 6.24 3.7224 4.82 3.46 4.46 4.87 3.526
## cvpred 4.182 3.73 3.22 8.22 4.0567 4.95 3.89 4.30 4.93 3.852
## Soma 4.000 1.50 1.50 4.00 4.0000 6.00 5.00 5.50 6.50 3.500
## CV residual -0.182 -2.23 -1.72 -4.22 -0.0567 1.05 1.11 1.20 1.57 -0.352
## 90 96 99 117 120 122 129
## Predicted 3.09 4.0 4.10 4.662 4.540 3.961 3.533
## cvpred 2.84 3.7 3.95 4.505 4.505 3.978 3.022
## Soma 4.00 5.0 5.00 5.000 5.500 4.000 3.500
## CV residual 1.16 1.3 1.05 0.495 0.995 0.022 0.478
##
## Sum of squares = 65.8 Mean square = 2.44 n = 27
##
## fold 4
## Observations in test set: 27
## 2 5 6 7 13 18 19 20 21 30
## Predicted 2.85 3.11 3.0951 4.42 3.9499 3.57 4.02 3.9901 2.43 3.74
## cvpred 2.86 2.97 2.9685 4.34 3.9465 3.43 3.87 3.9281 2.35 3.73
## Soma 4.00 1.50 3.0000 6.00 4.0000 2.00 7.00 4.0000 1.00 1.50
## CV residual 1.14 -1.47 0.0315 1.66 0.0535 -1.43 3.13 0.0719 -1.35 -2.23
## 33 37 49 73 92 94 104 105 107
## Predicted 2.944 2.614 3.51 3.62 5.0705 3.699 4.259 3.941 3.874
## cvpred 2.858 2.475 3.57 3.54 5.0107 3.745 4.236 3.883 3.813
## Soma 3.000 2.000 2.00 5.00 5.0000 4.500 4.000 4.500 4.500
## CV residual 0.142 -0.475 -1.57 1.46 -0.0107 0.755 -0.236 0.617 0.687
## 110 114 115 116 118 126 128 134
## Predicted 3.824 4.419 2.81 2.07 3.64 2.81 3.96 6.362
## cvpred 3.788 4.366 2.71 1.90 3.47 2.66 3.84 6.437
## Soma 3.500 4.000 4.00 5.00 5.00 4.00 5.00 7.000
## CV residual -0.288 -0.366 1.29 3.10 1.53 1.34 1.16 0.563
##
## Sum of squares = 48.5 Mean square = 1.79 n = 27
##
## fold 5
## Observations in test set: 27
## 1 4 11 24 26 27 28 29 31 32
## Predicted 4.91 3.83 3.196 3.693 3.64 3.186 3.44 4.39 4.44 6.426
## cvpred 4.79 3.67 3.171 3.769 3.72 3.058 3.58 4.66 4.46 6.163
## Soma 7.00 2.00 3.000 3.000 1.00 4.000 2.00 3.00 1.50 6.000
## CV residual 2.21 -1.67 -0.171 -0.769 -2.72 0.942 -1.58 -1.66 -2.96 -0.163
## 41 44 46 59 61 69 71 78 83 87
## Predicted 2.854 3.6154 3.31 3.1579 3.092 3.86 3.04 3.77 3.56 3.77
## cvpred 2.677 3.4117 3.42 3.0439 3.189 3.54 3.08 3.61 3.40 3.67
## Soma 2.000 3.5000 2.00 3.0000 3.000 5.50 4.50 5.00 4.50 6.00
## CV residual -0.677 0.0883 -1.42 -0.0439 -0.189 1.96 1.42 1.39 1.10 2.33
## 89 93 109 112 113 130 131
## Predicted 3.65 4.707 4.25 3.931 4.722 4.28 4.001
## cvpred 3.64 4.771 4.12 4.054 4.601 4.09 4.046
## Soma 4.50 4.500 5.50 5.000 4.500 5.50 5.000
## CV residual 0.86 -0.271 1.38 0.946 -0.101 1.41 0.954
##
## Sum of squares = 54.1 Mean square = 2 n = 27
##
## Overall (Sum over all 27 folds)
## ms
## 1.71
# part c: Scatter plot matrix
plot(~WT18+HT18++ST18+LG18+Sex+Soma,data=dat1,pch=c(16,18)[as.factor(dat1$Sex)],col=c("red","blue")[as.factor(dat1$Sex)])

# part d: Fit model
modeld.lm=lm(Soma~factor(Sex),data=dat1)
summary(modeld.lm)
##
## Call:
## lm(formula = Soma ~ factor(Sex), data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.091 -0.779 -0.091 0.721 3.909
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.091 0.143 21.59 < 2e-16 ***
## factor(Sex)1 1.688 0.200 8.46 4.1e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.16 on 134 degrees of freedom
## Multiple R-squared: 0.348, Adjusted R-squared: 0.343
## F-statistic: 71.5 on 1 and 134 DF, p-value: 4.12e-14
anova(modeld.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## factor(Sex) 1 96.8 96.8 71.5 4.1e-14 ***
## Residuals 134 181.3 1.4
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model 1 - Coincident Regressions
modeld1.lm=lm(Soma~WT18*factor(Sex)+HT18*factor(Sex)+ST18*factor(Sex)+LG18*factor(Sex),data=dat1)
summary(modeld1.lm)
##
## Call:
## lm(formula = Soma ~ WT18 * factor(Sex) + HT18 * factor(Sex) +
## ST18 * factor(Sex) + LG18 * factor(Sex), data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.0026 -0.3936 0.0281 0.3707 2.6393
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.66246 3.66374 3.46 0.00075 ***
## WT18 0.11802 0.02232 5.29 5.3e-07 ***
## factor(Sex)1 -2.28727 4.79345 -0.48 0.63407
## HT18 -0.07871 0.01674 -4.70 6.7e-06 ***
## ST18 -0.02145 0.00361 -5.93 2.7e-08 ***
## LG18 0.02128 0.08296 0.26 0.79802
## WT18:factor(Sex)1 -0.02338 0.02930 -0.80 0.42640
## factor(Sex)1:HT18 0.01825 0.02461 0.74 0.45964
## factor(Sex)1:ST18 0.01926 0.00663 2.91 0.00431 **
## factor(Sex)1:LG18 -0.04706 0.10194 -0.46 0.64518
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.757 on 126 degrees of freedom
## Multiple R-squared: 0.74, Adjusted R-squared: 0.722
## F-statistic: 39.9 on 9 and 126 DF, p-value: <2e-16
anova(modeld1.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT18 1 3.9 3.9 6.83 0.0100 *
## factor(Sex) 1 154.3 154.3 269.13 < 2e-16 ***
## HT18 1 26.0 26.0 45.29 5.4e-10 ***
## ST18 1 14.8 14.8 25.74 1.4e-06 ***
## LG18 1 0.0 0.0 0.05 0.8208
## WT18:factor(Sex) 1 0.8 0.8 1.43 0.2335
## factor(Sex):HT18 1 1.1 1.1 1.93 0.1669
## factor(Sex):ST18 1 4.7 4.7 8.24 0.0048 **
## factor(Sex):LG18 1 0.1 0.1 0.21 0.6452
## Residuals 126 72.2 0.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model 2 - Parallel
modeld2.lm=lm(Soma~WT18+HT18+ST18+LG18+factor(Sex),data=dat1)
summary(modeld2.lm)
##
## Call:
## lm(formula = Soma ~ WT18 + HT18 + ST18 + LG18 + factor(Sex),
## data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.1315 -0.4323 0.0571 0.3598 2.6656
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 11.03816 2.41175 4.58 1.1e-05 ***
## WT18 0.10318 0.01424 7.25 3.4e-11 ***
## HT18 -0.06924 0.01242 -5.57 1.4e-07 ***
## ST18 -0.01506 0.00306 -4.92 2.6e-06 ***
## LG18 0.01074 0.04874 0.22 0.826
## factor(Sex)1 0.60194 0.30308 1.99 0.049 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.78 on 130 degrees of freedom
## Multiple R-squared: 0.716, Adjusted R-squared: 0.705
## F-statistic: 65.5 on 5 and 130 DF, p-value: <2e-16
anova(modeld2.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT18 1 3.9 3.9 6.44 0.012 *
## HT18 1 130.0 130.0 213.85 <2e-16 ***
## ST18 1 62.4 62.4 102.57 <2e-16 ***
## LG18 1 0.3 0.3 0.54 0.465
## factor(Sex) 1 2.4 2.4 3.94 0.049 *
## Residuals 130 79.0 0.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model 3 - Common Intercept
modeld3.lm=lm(Soma~WT18+WT18:factor(Sex)+HT18+HT18:factor(Sex)+ST18+ST18:factor(Sex)+LG18+LG18:factor(Sex),data=dat1)
summary(modeld3.lm)
##
## Call:
## lm(formula = Soma ~ WT18 + WT18:factor(Sex) + HT18 + HT18:factor(Sex) +
## ST18 + ST18:factor(Sex) + LG18 + LG18:factor(Sex), data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.0147 -0.3893 0.0159 0.3832 2.6350
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 11.32627 2.35531 4.81 4.2e-06 ***
## WT18 0.11257 0.01912 5.89 3.3e-08 ***
## HT18 -0.07343 0.01253 -5.86 3.8e-08 ***
## ST18 -0.02142 0.00360 -5.95 2.5e-08 ***
## LG18 0.04244 0.06990 0.61 0.5449
## WT18:factor(Sex)1 -0.01464 0.02281 -0.64 0.5220
## factor(Sex)1:HT18 0.00803 0.01206 0.67 0.5070
## factor(Sex)1:ST18 0.01945 0.00659 2.95 0.0038 **
## factor(Sex)1:LG18 -0.07807 0.07829 -1.00 0.3205
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.755 on 127 degrees of freedom
## Multiple R-squared: 0.74, Adjusted R-squared: 0.723
## F-statistic: 45.1 on 8 and 127 DF, p-value: <2e-16
anova(modeld3.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT18 1 3.9 3.9 6.87 0.0098 **
## HT18 1 130.0 130.0 228.10 <2e-16 ***
## ST18 1 62.4 62.4 109.41 <2e-16 ***
## LG18 1 0.3 0.3 0.57 0.4508
## WT18:factor(Sex) 1 1.4 1.4 2.47 0.1185
## factor(Sex):HT18 1 2.5 2.5 4.32 0.0396 *
## factor(Sex):ST18 1 4.6 4.6 8.08 0.0052 **
## factor(Sex):LG18 1 0.6 0.6 0.99 0.3205
## Residuals 127 72.4 0.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model 4 - No Restrcition
modeld4.lm=lm(Soma~WT18+HT18+ST18+LG18,data=dat1)
summary(modeld4.lm)
##
## Call:
## lm(formula = Soma ~ WT18 + HT18 + ST18 + LG18, data = dat1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.0080 -0.4366 0.0458 0.3629 2.6544
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.3447 2.3462 5.26 5.7e-07 ***
## WT18 0.0994 0.0143 6.97 1.4e-10 ***
## HT18 -0.0740 0.0123 -6.01 1.7e-08 ***
## ST18 -0.0197 0.0020 -9.87 < 2e-16 ***
## LG18 0.0346 0.0478 0.72 0.47
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.788 on 131 degrees of freedom
## Multiple R-squared: 0.707, Adjusted R-squared: 0.698
## F-statistic: 79.1 on 4 and 131 DF, p-value: <2e-16
anova(modeld4.lm)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT18 1 3.9 3.9 6.30 0.013 *
## HT18 1 130.0 130.0 209.15 <2e-16 ***
## ST18 1 62.4 62.4 100.32 <2e-16 ***
## LG18 1 0.3 0.3 0.52 0.470
## Residuals 131 81.4 0.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Compare Models using F Tests
anova(modeld2.lm,modeld1.lm)
## Analysis of Variance Table
##
## Model 1: Soma ~ WT18 + HT18 + ST18 + LG18 + factor(Sex)
## Model 2: Soma ~ WT18 * factor(Sex) + HT18 * factor(Sex) + ST18 * factor(Sex) +
## LG18 * factor(Sex)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 130 79.0
## 2 126 72.2 4 6.78 2.96 0.023 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(modeld3.lm,modeld1.lm)
## Analysis of Variance Table
##
## Model 1: Soma ~ WT18 + WT18:factor(Sex) + HT18 + HT18:factor(Sex) + ST18 +
## ST18:factor(Sex) + LG18 + LG18:factor(Sex)
## Model 2: Soma ~ WT18 * factor(Sex) + HT18 * factor(Sex) + ST18 * factor(Sex) +
## LG18 * factor(Sex)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 127 72.4
## 2 126 72.2 1 0.131 0.23 0.63
anova(modeld4.lm,modeld1.lm)
## Analysis of Variance Table
##
## Model 1: Soma ~ WT18 + HT18 + ST18 + LG18
## Model 2: Soma ~ WT18 * factor(Sex) + HT18 * factor(Sex) + ST18 * factor(Sex) +
## LG18 * factor(Sex)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 131 81.4
## 2 126 72.2 5 9.18 3.2 0.0094 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(modeld.lm,modeld1.lm)
## Analysis of Variance Table
##
## Model 1: Soma ~ factor(Sex)
## Model 2: Soma ~ WT18 * factor(Sex) + HT18 * factor(Sex) + ST18 * factor(Sex) +
## LG18 * factor(Sex)
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 134 181.3
## 2 126 72.2 8 109 23.8 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Cross Validation
cv5res1=cv.lm(data=dat1,modeld1.lm,m=5)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT18 1 3.9 3.9 6.83 0.0100 *
## factor(Sex) 1 154.3 154.3 269.13 < 2e-16 ***
## HT18 1 26.0 26.0 45.29 5.4e-10 ***
## ST18 1 14.8 14.8 25.74 1.4e-06 ***
## LG18 1 0.0 0.0 0.05 0.8208
## WT18:factor(Sex) 1 0.8 0.8 1.43 0.2335
## factor(Sex):HT18 1 1.1 1.1 1.93 0.1669
## factor(Sex):ST18 1 4.7 4.7 8.24 0.0048 **
## factor(Sex):LG18 1 0.1 0.1 0.21 0.6452
## Residuals 126 72.2 0.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = dat1, modeld1.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 27
## 10 12 17 25 34 39 43 48 51 63
## Predicted 2.793 1.35 3.220 1.714 2.589 4.47 2.64 3.724 2.1520 3.00
## cvpred 2.895 1.04 3.159 1.609 2.118 4.47 2.49 3.589 2.0782 3.03
## Soma 3.000 3.00 2.500 2.000 3.000 6.00 3.00 4.000 2.0000 1.00
## CV residual 0.105 1.96 -0.659 0.391 0.882 1.53 0.51 0.411 -0.0782 -2.03
## 66 68 70 74 77 79 81 85 86 97
## Predicted 1.84 3.9347 5.131 4.219 4.749 5.029 4.70 5.442 4.5405 5.626
## cvpred 1.66 3.9806 5.031 4.333 4.737 4.989 4.74 5.367 4.5268 5.581
## Soma 3.00 4.0000 5.500 4.000 5.000 5.500 5.00 5.500 4.5000 6.000
## CV residual 1.34 0.0194 0.469 -0.333 0.263 0.511 0.26 0.133 -0.0268 0.419
## 100 103 111 119 123 124 135
## Predicted 4.631 4.73 4.31 5.004 3.96 4.924 5.327
## cvpred 4.616 4.74 4.34 4.971 4.03 4.903 5.235
## Soma 5.000 5.00 4.00 5.500 3.00 4.500 5.500
## CV residual 0.384 0.26 -0.34 0.529 -1.03 -0.403 0.265
##
## Sum of squares = 16.8 Mean square = 0.62 n = 27
##
## fold 2
## Observations in test set: 28
## 3 9 16 23 35 36 42 52 56 58
## Predicted 3.36 3.508 3.9879 3.178 4.403 3.962 2.651 3.15 1.904 3.54
## cvpred 3.31 3.496 3.9513 3.147 4.461 3.841 2.794 3.35 1.882 3.64
## Soma 6.00 4.000 4.0000 4.000 3.500 4.000 3.000 2.00 1.500 2.00
## CV residual 2.69 0.504 0.0487 0.853 -0.961 0.159 0.206 -1.35 -0.382 -1.64
## 65 67 72 80 88 91 95 98 101
## Predicted 2.665 4.9491 3.797 4.319 5.151 4.23 4.670 4.907 4.9818
## cvpred 2.628 4.9129 3.862 4.395 5.133 4.29 4.686 4.895 5.0102
## Soma 3.000 5.0000 3.000 4.000 5.000 4.00 5.000 4.500 5.0000
## CV residual 0.372 0.0871 -0.862 -0.395 -0.133 -0.29 0.314 -0.395 -0.0102
## 102 106 108 121 125 127 132 133 136
## Predicted 4.323 4.466 6.417 4.446 4.258 5.05 4.37 4.4271 4.830
## cvpred 4.333 4.502 6.293 4.474 4.307 5.04 4.44 4.4545 4.825
## Soma 4.000 4.000 6.500 4.000 5.000 6.50 4.00 4.5000 5.500
## CV residual -0.333 -0.502 0.207 -0.474 0.693 1.46 -0.44 0.0455 0.675
##
## Sum of squares = 19.2 Mean square = 0.69 n = 28
##
## fold 3
## Observations in test set: 27
## 8 14 15 22 38 40 45 47 50 53
## Predicted 3.585 3.284 3.97 2.686 3.01 2.73 3.3952 3.11 3.857 2.19
## cvpred 3.568 3.327 4.02 2.869 3.04 2.90 3.4053 3.23 3.831 2.31
## Soma 4.000 3.000 2.50 3.000 2.00 1.50 3.5000 2.00 4.000 1.00
## CV residual 0.432 -0.327 -1.52 0.131 -1.04 -1.40 0.0947 -1.23 0.169 -1.31
## 54 55 57 60 62 64 75 76 82
## Predicted 3.9353 1.5067 1.914 3.880 3.270 5.224 4.88 5.4884 5.951
## cvpred 3.9666 1.5859 2.061 3.858 3.369 5.219 4.86 5.5261 5.848
## Soma 4.0000 1.5000 1.500 4.000 4.000 6.000 5.00 5.5000 6.500
## CV residual 0.0334 -0.0859 -0.561 0.142 0.631 0.781 0.14 -0.0261 0.652
## 84 90 96 99 117 120 122 129
## Predicted 4.048 4.28 4.604 4.767 5.07 5.008 4.443 4.203
## cvpred 4.098 4.33 4.614 4.761 5.08 4.962 4.507 4.275
## Soma 3.500 4.00 5.000 5.000 5.00 5.500 4.000 3.500
## CV residual -0.598 -0.33 0.386 0.239 -0.08 0.538 -0.507 -0.775
##
## Sum of squares = 12.6 Mean square = 0.47 n = 27
##
## fold 4
## Observations in test set: 27
## 2 5 6 7 13 18 19 20 21 30
## Predicted 2.04 2.107 2.578 5.886 2.76 2.945 5.44 2.81 2.21 1.5573
## cvpred 1.90 2.164 2.515 5.841 2.70 2.851 5.26 2.73 2.08 1.5331
## Soma 4.00 1.500 3.000 6.000 4.00 2.000 7.00 4.00 1.00 1.5000
## CV residual 2.10 -0.664 0.485 0.159 1.30 -0.851 1.74 1.27 -1.08 -0.0331
## 33 37 49 73 92 94 104 105 107
## Predicted 2.535 1.935 3.31 4.440 5.121 4.608 4.1540 4.5715 4.368
## cvpred 2.485 1.823 3.24 4.334 5.216 4.609 3.9744 4.5901 4.247
## Soma 3.000 2.000 2.00 5.000 5.000 4.500 4.0000 4.5000 4.500
## CV residual 0.515 0.177 -1.24 0.666 -0.216 -0.109 0.0256 -0.0901 0.253
## 110 114 115 116 118 126 128 134
## Predicted 4.018 4.296 4.10027 4.369 5.010 4.303 4.919 8.41
## cvpred 3.725 4.139 4.00383 4.178 5.028 4.201 5.143 9.81
## Soma 3.500 4.000 4.00000 5.000 5.000 4.000 5.000 7.00
## CV residual -0.225 -0.139 -0.00383 0.822 -0.028 -0.201 -0.143 -2.81
##
## Sum of squares = 24.4 Mean square = 0.9 n = 27
##
## fold 5
## Observations in test set: 27
## 1 4 11 24 26 27 28 29 31 32
## Predicted 7.670 3.46 2.314 2.385 1.93 3.642 2.772 3.296 3.07 5.070
## cvpred 7.866 3.55 2.242 2.486 1.92 3.569 2.908 3.688 3.25 5.155
## Soma 7.000 2.00 3.000 3.000 1.00 4.000 2.000 3.000 1.50 6.000
## CV residual -0.866 -1.55 0.758 0.514 -0.92 0.431 -0.908 -0.688 -1.75 0.845
## 41 44 46 59 61 69 71 78 83
## Predicted 2.390 2.23 2.475 2.915 2.9366 4.585 4.671 4.750 4.5749
## cvpred 2.499 2.18 2.609 2.857 3.0565 4.615 4.693 4.662 4.5413
## Soma 2.000 3.50 2.000 3.000 3.0000 5.500 4.500 5.000 4.5000
## CV residual -0.499 1.32 -0.609 0.143 -0.0565 0.885 -0.193 0.338 -0.0413
## 87 89 93 109 112 113 130 131
## Predicted 5.593 4.861 4.906 5.834 5.0336 4.5913 4.722 5.1062
## cvpred 5.474 4.853 5.004 5.823 5.0416 4.5207 4.679 5.0325
## Soma 6.000 4.500 4.500 5.500 5.0000 4.5000 5.500 5.0000
## CV residual 0.526 -0.353 -0.504 -0.323 -0.0416 -0.0207 0.821 -0.0325
##
## Sum of squares = 14.9 Mean square = 0.55 n = 27
##
## Overall (Sum over all 27 folds)
## ms
## 0.646
cv5res1=cv.lm(data=dat1,modeld2.lm,m=5)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT18 1 3.9 3.9 6.44 0.012 *
## HT18 1 130.0 130.0 213.85 <2e-16 ***
## ST18 1 62.4 62.4 102.57 <2e-16 ***
## LG18 1 0.3 0.3 0.54 0.465
## factor(Sex) 1 2.4 2.4 3.94 0.049 *
## Residuals 130 79.0 0.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = dat1, modeld2.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 27
## 10 12 17 25 34 39 43 48 51 63
## Predicted 2.737 1.57 3.269 1.859 2.462 4.37 2.81 3.697 2.348 3.13
## cvpred 2.819 1.47 3.205 1.845 2.298 4.29 2.71 3.596 2.303 3.11
## Soma 3.000 3.00 2.500 2.000 3.000 6.00 3.00 4.000 2.000 1.00
## CV residual 0.181 1.53 -0.705 0.155 0.702 1.71 0.29 0.404 -0.303 -2.11
## 66 68 70 74 77 79 81 85 86 97
## Predicted 2.16 3.896 5.014 4.619 4.872 5.03 4.9854 5.655 4.62 6.048
## cvpred 2.06 3.893 5.013 4.639 4.887 5.10 5.0188 5.699 4.66 6.106
## Soma 3.00 4.000 5.500 4.000 5.000 5.50 5.0000 5.500 4.50 6.000
## CV residual 0.94 0.107 0.487 -0.639 0.113 0.40 -0.0188 -0.199 -0.16 -0.106
## 100 103 111 119 123 124 135
## Predicted 4.506 4.802 4.453 4.926 3.94 4.973 5.266
## cvpred 4.511 4.748 4.444 4.981 4.03 4.991 5.282
## Soma 5.000 5.000 4.000 5.500 3.00 4.500 5.500
## CV residual 0.489 0.252 -0.444 0.519 -1.03 -0.491 0.218
##
## Sum of squares = 15 Mean square = 0.56 n = 27
##
## fold 2
## Observations in test set: 28
## 3 9 16 23 35 36 42 52 56 58
## Predicted 3.33 3.364 3.911 3.044 4.155 3.70 2.659 2.98 2.141 3.45
## cvpred 3.25 3.418 3.802 3.041 4.172 3.74 2.764 3.14 2.159 3.48
## Soma 6.00 4.000 4.000 4.000 3.500 4.00 3.000 2.00 1.500 2.00
## CV residual 2.75 0.582 0.198 0.959 -0.672 0.26 0.236 -1.14 -0.659 -1.48
## 65 67 72 80 88 91 95 98 101
## Predicted 2.640 4.727 3.557 4.59 5.311 4.413 4.686 4.811 5.425
## cvpred 2.656 4.825 3.624 4.70 5.451 4.586 4.795 4.758 5.586
## Soma 3.000 5.000 3.000 4.00 5.000 4.000 5.000 4.500 5.000
## CV residual 0.344 0.175 -0.624 -0.70 -0.451 -0.586 0.205 -0.258 -0.586
## 102 106 108 121 125 127 132 133 136
## Predicted 3.879 4.583 6.5709 4.49 4.24 5.22 4.714 4.30 4.704
## cvpred 3.728 4.744 6.5647 4.67 4.32 5.30 4.767 4.34 4.699
## Soma 4.000 4.000 6.5000 4.00 5.00 6.50 4.000 4.50 5.500
## CV residual 0.272 -0.744 -0.0647 -0.67 0.68 1.20 -0.767 0.16 0.801
##
## Sum of squares = 19.6 Mean square = 0.7 n = 28
##
## fold 3
## Observations in test set: 27
## 8 14 15 22 38 40 45 47 50 53
## Predicted 3.350 3.292 3.82 2.8342 2.886 2.94 3.231 3.06 3.640 2.38
## cvpred 3.322 3.372 3.84 2.9697 2.897 3.09 3.219 3.11 3.628 2.51
## Soma 4.000 3.000 2.50 3.0000 2.000 1.50 3.500 2.00 4.000 1.00
## CV residual 0.678 -0.372 -1.34 0.0303 -0.897 -1.59 0.281 -1.11 0.372 -1.51
## 54 55 57 60 62 64 75 76 82 84
## Predicted 3.676 1.865 2.01 3.83 3.227 4.93 5.01159 5.658 6.372 3.635
## cvpred 3.653 2.037 2.09 3.87 3.288 4.90 4.99669 5.599 6.259 3.751
## Soma 4.000 1.500 1.50 4.00 4.000 6.00 5.00000 5.500 6.500 3.500
## CV residual 0.347 -0.537 -0.59 0.13 0.712 1.10 0.00331 -0.099 0.241 -0.251
## 90 96 99 117 120 122 129
## Predicted 4.0308 4.444 4.882 5.198 5.046 4.248 4.068
## cvpred 4.0714 4.476 4.878 5.171 5.027 4.284 4.083
## Soma 4.0000 5.000 5.000 5.000 5.500 4.000 3.500
## CV residual -0.0714 0.524 0.122 -0.171 0.473 -0.284 -0.583
##
## Sum of squares = 13.1 Mean square = 0.48 n = 27
##
## fold 4
## Observations in test set: 27
## 2 5 6 7 13 18 19 20 21 30
## Predicted 2.31 2.231 2.646 5.293 2.78 3.055 5.18 2.89 2.45 1.831
## cvpred 2.18 2.194 2.528 5.461 2.69 2.999 5.30 2.81 2.32 1.698
## Soma 4.00 1.500 3.000 6.000 4.00 2.000 7.00 4.00 1.00 1.500
## CV residual 1.82 -0.694 0.472 0.539 1.31 -0.999 1.70 1.19 -1.32 -0.198
## 33 37 49 73 92 94 104 105 107
## Predicted 2.646 2.2195 3.20 4.27 5.324 4.594 3.895 4.5322 4.5374
## cvpred 2.572 2.0639 3.16 4.22 5.325 4.634 3.822 4.5685 4.5413
## Soma 3.000 2.0000 2.00 5.00 5.000 4.500 4.000 4.5000 4.5000
## CV residual 0.428 -0.0639 -1.16 0.78 -0.325 -0.134 0.178 -0.0685 -0.0413
## 110 114 115 116 118 126 128 134
## Predicted 3.761 4.231 3.807 3.77 4.942 3.929 4.703 9.02
## cvpred 3.666 4.175 3.804 3.64 4.885 3.852 4.738 9.41
## Soma 3.500 4.000 4.000 5.00 5.000 4.000 5.000 7.00
## CV residual -0.166 -0.175 0.196 1.36 0.115 0.148 0.262 -2.41
##
## Sum of squares = 23.3 Mean square = 0.86 n = 27
##
## fold 5
## Observations in test set: 27
## 1 4 11 24 26 27 28 29 31 32
## Predicted 7.084 3.44 2.367 2.381 2.15 3.410 2.832 3.335 3.07 4.81
## cvpred 7.112 3.50 2.386 2.453 2.19 3.403 2.918 3.505 3.17 4.84
## Soma 7.000 2.00 3.000 3.000 1.00 4.000 2.000 3.000 1.50 6.00
## CV residual -0.112 -1.50 0.614 0.547 -1.19 0.597 -0.918 -0.505 -1.67 1.16
## 41 44 46 59 61 69 71 78 83
## Predicted 2.624 2.527 2.627 2.9111 2.9435 4.34 4.34 5.0117 4.517
## cvpred 2.703 2.559 2.714 2.9275 3.0192 4.33 4.35 4.9031 4.446
## Soma 2.000 3.500 2.000 3.0000 3.0000 5.50 4.50 5.0000 4.500
## CV residual -0.703 0.941 -0.714 0.0725 -0.0192 1.17 0.15 0.0969 0.054
## 87 89 93 109 112 113 130 131
## Predicted 5.940 4.879 4.304 6.27 4.891 4.4956 4.680 5.0991
## cvpred 5.839 4.828 4.377 6.26 4.889 4.4101 4.633 5.0241
## Soma 6.000 4.500 4.500 5.50 5.000 4.5000 5.500 5.0000
## CV residual 0.161 -0.328 0.123 -0.76 0.111 0.0899 0.867 -0.0241
##
## Sum of squares = 14.7 Mean square = 0.55 n = 27
##
## Overall (Sum over all 27 folds)
## ms
## 0.63
cv5res1=cv.lm(data=dat1,modeld3.lm,m=5)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT18 1 3.9 3.9 6.87 0.0098 **
## HT18 1 130.0 130.0 228.10 <2e-16 ***
## ST18 1 62.4 62.4 109.41 <2e-16 ***
## LG18 1 0.3 0.3 0.57 0.4508
## WT18:factor(Sex) 1 1.4 1.4 2.47 0.1185
## factor(Sex):HT18 1 2.5 2.5 4.32 0.0396 *
## factor(Sex):ST18 1 4.6 4.6 8.08 0.0052 **
## factor(Sex):LG18 1 0.6 0.6 0.99 0.3205
## Residuals 127 72.4 0.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = dat1, modeld3.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 27
## 10 12 17 25 34 39 43 48 51 63
## Predicted 2.800 1.33 3.225 1.733 2.507 4.47 2.633 3.675 2.1819 3.01
## cvpred 2.894 1.05 3.158 1.607 2.136 4.47 2.492 3.598 2.0731 3.03
## Soma 3.000 3.00 2.500 2.000 3.000 6.00 3.000 4.000 2.0000 1.00
## CV residual 0.106 1.95 -0.658 0.393 0.864 1.53 0.508 0.402 -0.0731 -2.03
## 66 68 70 74 77 79 81 85 86 97
## Predicted 1.84 3.920 5.112 4.232 4.736 5.000 4.701 5.414 4.4963 5.612
## cvpred 1.66 3.984 5.036 4.331 4.741 4.995 4.741 5.373 4.5364 5.585
## Soma 3.00 4.000 5.500 4.000 5.000 5.500 5.000 5.500 4.5000 6.000
## CV residual 1.34 0.016 0.464 -0.331 0.259 0.505 0.259 0.127 -0.0364 0.415
## 100 103 111 119 123 124 135
## Predicted 4.637 4.780 4.301 4.997 3.92 4.927 5.319
## cvpred 4.615 4.731 4.342 4.973 4.04 4.903 5.237
## Soma 5.000 5.000 4.000 5.500 3.00 4.500 5.500
## CV residual 0.385 0.269 -0.342 0.527 -1.04 -0.403 0.263
##
## Sum of squares = 16.7 Mean square = 0.62 n = 27
##
## fold 2
## Observations in test set: 28
## 3 9 16 23 35 36 42 52 56
## Predicted 3.36 3.525 3.9777 3.189 4.376 4.0266 2.609 3.09 1.925
## cvpred 3.31 3.555 3.9154 3.176 4.388 4.0394 2.681 3.19 1.946
## Soma 6.00 4.000 4.0000 4.000 3.500 4.0000 3.000 2.00 1.500
## CV residual 2.69 0.445 0.0846 0.824 -0.888 -0.0394 0.319 -1.19 -0.446
## 58 65 67 72 80 88 91 95 98
## Predicted 3.49 2.686 4.9901 3.801 4.289 5.190 4.252 4.677 4.890
## cvpred 3.52 2.689 5.0436 3.883 4.355 5.275 4.402 4.737 4.842
## Soma 2.00 3.000 5.0000 3.000 4.000 5.000 4.000 5.000 4.500
## CV residual -1.52 0.311 -0.0436 -0.883 -0.355 -0.275 -0.402 0.263 -0.342
## 101 102 106 108 121 125 127 132 133
## Predicted 4.9885 4.285 4.497 6.443 4.494 4.252 5.09 4.361 4.41
## cvpred 5.0814 4.188 4.626 6.372 4.644 4.314 5.16 4.436 4.43
## Soma 5.0000 4.000 4.000 6.500 4.000 5.000 6.50 4.000 4.50
## CV residual -0.0814 -0.188 -0.626 0.128 -0.644 0.686 1.34 -0.436 0.07
## 136
## Predicted 4.808
## cvpred 4.772
## Soma 5.500
## CV residual 0.728
##
## Sum of squares = 18.2 Mean square = 0.65 n = 28
##
## fold 3
## Observations in test set: 27
## 8 14 15 22 38 40 45 47 50 53
## Predicted 3.61 3.324 3.94 2.653 3.02 2.70 3.3966 3.09 3.8955 2.19
## cvpred 3.63 3.407 3.98 2.798 3.08 2.83 3.4133 3.19 3.9145 2.31
## Soma 4.00 3.000 2.50 3.000 2.00 1.50 3.5000 2.00 4.0000 1.00
## CV residual 0.37 -0.407 -1.48 0.202 -1.08 -1.33 0.0867 -1.19 0.0855 -1.31
## 54 55 57 60 62 64 75 76 82
## Predicted 3.9267 1.561 1.874 3.9199 3.259 5.189 4.881 5.402 5.967
## cvpred 3.9548 1.692 1.982 3.9405 3.348 5.153 4.865 5.308 5.863
## Soma 4.0000 1.500 1.500 4.0000 4.000 6.000 5.000 5.500 6.500
## CV residual 0.0452 -0.192 -0.482 0.0595 0.652 0.847 0.135 0.192 0.637
## 84 90 96 99 117 120 122 129
## Predicted 4.090 4.277 4.628 4.77 5.0389 5.049 4.416 4.162
## cvpred 4.212 4.331 4.671 4.76 4.9977 5.052 4.447 4.182
## Soma 3.500 4.000 5.000 5.00 5.0000 5.500 4.000 3.500
## CV residual -0.712 -0.331 0.329 0.24 0.0023 0.448 -0.447 -0.682
##
## Sum of squares = 12.1 Mean square = 0.45 n = 27
##
## fold 4
## Observations in test set: 27
## 2 5 6 7 13 18 19 20 21 30
## Predicted 2.07 2.034 2.618 5.865 2.79 2.929 5.39 2.82 2.23 1.5502
## cvpred 1.88 2.197 2.495 5.854 2.68 2.858 5.28 2.73 2.07 1.5323
## Soma 4.00 1.500 3.000 6.000 4.00 2.000 7.00 4.00 1.00 1.5000
## CV residual 2.12 -0.697 0.505 0.146 1.32 -0.858 1.72 1.27 -1.07 -0.0323
## 33 37 49 73 92 94 104 105 107
## Predicted 2.526 1.964 3.36 4.43 5.11 4.609 4.1535 4.5871 4.356
## cvpred 2.487 1.805 3.21 4.34 5.22 4.609 3.9783 4.5826 4.256
## Soma 3.000 2.000 2.00 5.00 5.00 4.500 4.0000 4.5000 4.500
## CV residual 0.513 0.195 -1.21 0.66 -0.22 -0.109 0.0217 -0.0826 0.244
## 110 114 115 116 118 126 128 134
## Predicted 3.986 4.286 4.1310 4.338 4.9842 4.319 4.984 8.48
## cvpred 3.746 4.147 3.9913 4.196 5.0393 4.196 5.107 9.74
## Soma 3.500 4.000 4.0000 5.000 5.0000 4.000 5.000 7.00
## CV residual -0.246 -0.147 0.0087 0.804 -0.0393 -0.196 -0.107 -2.74
##
## Sum of squares = 24.1 Mean square = 0.89 n = 27
##
## fold 5
## Observations in test set: 27
## 1 4 11 24 26 27 28 29 31 32
## Predicted 7.618 3.46 2.293 2.44 1.938 3.62 2.794 3.376 3.10 5.034
## cvpred 7.904 3.55 2.249 2.46 1.919 3.58 2.895 3.649 3.24 5.177
## Soma 7.000 2.00 3.000 3.00 1.000 4.00 2.000 3.000 1.50 6.000
## CV residual -0.904 -1.55 0.751 0.54 -0.919 0.42 -0.895 -0.649 -1.74 0.823
## 41 44 46 59 61 69 71 78 83
## Predicted 2.399 2.18 2.501 2.879 2.9593 4.60 4.66 4.775 4.5978
## cvpred 2.495 2.20 2.596 2.872 3.0446 4.61 4.70 4.651 4.5325
## Soma 2.000 3.50 2.000 3.000 3.0000 5.50 4.50 5.000 4.5000
## CV residual -0.495 1.30 -0.596 0.128 -0.0446 0.89 -0.20 0.349 -0.0325
## 87 89 93 109 112 113 130 131
## Predicted 5.594 4.889 4.890 5.846 5.0289 4.5981 4.720 5.1064
## cvpred 5.472 4.842 5.012 5.817 5.0436 4.5174 4.679 5.0316
## Soma 6.000 4.500 4.500 5.500 5.0000 4.5000 5.500 5.0000
## CV residual 0.528 -0.342 -0.512 -0.317 -0.0436 -0.0174 0.821 -0.0316
##
## Sum of squares = 14.7 Mean square = 0.54 n = 27
##
## Overall (Sum over all 27 folds)
## ms
## 0.631
cv5res1=cv.lm(data=dat1,modeld4.lm,m=5)
## Analysis of Variance Table
##
## Response: Soma
## Df Sum Sq Mean Sq F value Pr(>F)
## WT18 1 3.9 3.9 6.30 0.013 *
## HT18 1 130.0 130.0 209.15 <2e-16 ***
## ST18 1 62.4 62.4 100.32 <2e-16 ***
## LG18 1 0.3 0.3 0.52 0.470
## Residuals 131 81.4 0.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Warning in cv.lm(data = dat1, modeld4.lm, m = 5):
##
## As there is >1 explanatory variable, cross-validation
## predicted values for a fold are not a linear function
## of corresponding overall predicted values. Lines that
## are shown for the different folds are approximate

##
## fold 1
## Observations in test set: 27
## 10 12 17 25 34 39 43 48 51 63
## Predicted 2.8197 1.68 3.258 1.9400 2.875 4.36 2.76 3.713 2.310 3.01
## cvpred 2.9291 1.61 3.176 1.9534 2.817 4.24 2.64 3.612 2.251 2.95
## Soma 3.0000 3.00 2.500 2.0000 3.000 6.00 3.00 4.000 2.000 1.00
## CV residual 0.0709 1.39 -0.676 0.0466 0.183 1.76 0.36 0.388 -0.251 -1.95
## 66 68 70 74 77 79 81 85 86
## Predicted 2.04 3.876 4.912 4.733 4.870 4.925 5.0284 5.646 4.613
## cvpred 1.91 3.882 4.866 4.804 4.875 4.965 5.0767 5.652 4.625
## Soma 3.00 4.000 5.500 4.000 5.000 5.500 5.0000 5.500 4.500
## CV residual 1.09 0.118 0.634 -0.804 0.125 0.535 -0.0767 -0.152 -0.125
## 97 100 103 111 119 123 124 135
## Predicted 6.097 4.403 4.797 4.495 4.792 3.868 4.920 5.159
## cvpred 6.137 4.402 4.769 4.497 4.826 3.956 4.931 5.136
## Soma 6.000 5.000 5.000 4.000 5.500 3.000 4.500 5.500
## CV residual -0.137 0.598 0.231 -0.497 0.674 -0.956 -0.431 0.364
##
## Sum of squares = 14.6 Mean square = 0.54 n = 27
##
## fold 2
## Observations in test set: 28
## 3 9 16 23 35 36 42 52 56
## Predicted 3.35 3.591 3.877 3.258 4.336 4.01635 2.8327 3.31 2.129
## cvpred 3.26 3.607 3.772 3.207 4.311 4.00369 2.9096 3.40 2.176
## Soma 6.00 4.000 4.000 4.000 3.500 4.00000 3.0000 2.00 1.500
## CV residual 2.74 0.393 0.228 0.793 -0.811 -0.00369 0.0904 -1.40 -0.676
## 58 65 67 72 80 88 91 95 98 101
## Predicted 3.56 2.817 4.61 3.46 4.709 5.35 4.506 4.687 4.679 5.595
## cvpred 3.57 2.803 4.76 3.57 4.826 5.50 4.679 4.826 4.665 5.746
## Soma 2.00 3.000 5.00 3.00 4.000 5.00 4.000 5.000 4.500 5.000
## CV residual -1.57 0.197 0.24 -0.57 -0.826 -0.50 -0.679 0.174 -0.165 -0.746
## 102 106 108 121 125 127 132 133 136
## Predicted 3.592 4.638 6.4945 4.522 4.229 5.22 4.799 4.226 4.600
## cvpred 3.509 4.808 6.5141 4.713 4.334 5.29 4.838 4.313 4.645
## Soma 4.000 4.000 6.5000 4.000 5.000 6.50 4.000 4.500 5.500
## CV residual 0.491 -0.808 -0.0141 -0.713 0.666 1.21 -0.838 0.187 0.855
##
## Sum of squares = 21.1 Mean square = 0.75 n = 28
##
## fold 3
## Observations in test set: 27
## 8 14 15 22 38 40 45 47 50
## Predicted 3.624 3.342 3.92 2.8359 3.11 2.81 3.3980 3.25 3.8594
## cvpred 3.663 3.444 3.97 2.9681 3.18 2.95 3.4347 3.34 3.9045
## Soma 4.000 3.000 2.50 3.0000 2.00 1.50 3.5000 2.00 4.0000
## CV residual 0.337 -0.444 -1.47 0.0319 -1.18 -1.45 0.0653 -1.34 0.0955
## 53 54 55 57 60 62 64 75 76
## Predicted 2.33 3.9650 1.638 2.096 3.773 3.363 4.98 5.0240 5.574
## cvpred 2.45 4.0021 1.791 2.194 3.833 3.453 4.98 5.0121 5.531
## Soma 1.00 4.0000 1.500 1.500 4.000 4.000 6.00 5.0000 5.500
## CV residual -1.45 -0.0021 -0.291 -0.694 0.167 0.547 1.02 -0.0121 -0.031
## 82 84 90 96 99 117 120 122 129
## Predicted 6.390 3.524 3.869 4.339 4.9026 5.169 4.984 4.11 3.928
## cvpred 6.291 3.603 3.885 4.348 4.9025 5.149 4.951 4.13 3.932
## Soma 6.500 3.500 4.000 5.000 5.0000 5.000 5.500 4.00 3.500
## CV residual 0.209 -0.103 0.115 0.652 0.0975 -0.149 0.549 -0.13 -0.432
##
## Sum of squares = 12.8 Mean square = 0.48 n = 27
##
## fold 4
## Observations in test set: 27
## 2 5 6 7 13 18 19 20 21 30
## Predicted 2.07 2.313 2.704 5.701 2.84 3.007 5.21 2.89 2.27 1.7510
## cvpred 1.95 2.228 2.555 5.816 2.71 2.947 5.36 2.80 2.15 1.5936
## Soma 4.00 1.500 3.000 6.000 4.00 2.000 7.00 4.00 1.00 1.5000
## CV residual 2.05 -0.728 0.445 0.184 1.29 -0.947 1.64 1.20 -1.15 -0.0936
## 33 37 49 73 92 94 104 105 107
## Predicted 2.641 2.0585 3.26 4.163 5.351 4.4969 3.780 4.4524 4.5538
## cvpred 2.545 1.9035 3.19 4.117 5.354 4.5381 3.707 4.4877 4.5408
## Soma 3.000 2.0000 2.00 5.000 5.000 4.5000 4.000 4.5000 4.5000
## CV residual 0.455 0.0965 -1.19 0.883 -0.354 -0.0381 0.293 0.0123 -0.0408
## 110 114 115 116 118 126 128 134
## Predicted 3.6110 4.184 3.662 3.46 4.857 3.783 4.615 9.01
## cvpred 3.5175 4.122 3.658 3.37 4.816 3.715 4.662 9.46
## Soma 3.5000 4.000 4.000 5.00 5.000 4.000 5.000 7.00
## CV residual -0.0175 -0.122 0.342 1.63 0.184 0.285 0.338 -2.46
##
## Sum of squares = 24.7 Mean square = 0.92 n = 27
##
## fold 5
## Observations in test set: 27
## 1 4 11 24 26 27 28 29 31 32
## Predicted 7.115 3.47 2.519 2.505 2.07 3.648 2.885 3.33 3.17 4.89
## cvpred 7.142 3.52 2.528 2.582 2.11 3.637 2.964 3.49 3.26 4.92
## Soma 7.000 2.00 3.000 3.000 1.00 4.000 2.000 3.00 1.50 6.00
## CV residual -0.142 -1.52 0.472 0.418 -1.11 0.363 -0.964 -0.49 -1.76 1.08
## 41 44 46 59 61 69 71 78 83
## Predicted 2.488 2.39 2.578 3.0539 3.0192 4.23 4.14 5.0475 4.456
## cvpred 2.571 2.42 2.666 3.0569 3.0909 4.21 4.16 4.9352 4.381
## Soma 2.000 3.50 2.000 3.0000 3.0000 5.50 4.50 5.0000 4.500
## CV residual -0.571 1.08 -0.666 -0.0569 -0.0909 1.29 0.34 0.0648 0.119
## 87 89 93 109 112 113 130 131
## Predicted 5.898 4.854 4.020 6.348 4.757 4.374 4.58 4.9661
## cvpred 5.809 4.793 4.093 6.321 4.755 4.296 4.54 4.9022
## Soma 6.000 4.500 4.500 5.500 5.000 4.500 5.50 5.0000
## CV residual 0.191 -0.293 0.407 -0.821 0.245 0.204 0.96 0.0978
##
## Sum of squares = 15.3 Mean square = 0.57 n = 27
##
## Overall (Sum over all 27 folds)
## ms
## 0.651