1. Load the penguins2 excel file into R, and convert the dataset into a data frame.

library(readxl)
#Penguins2 dataset loaded in and labeled peng2
peng2 <- read_excel("G:/Other computers/My Laptop/Documents/Richard 621/Week 10/penguins2.xlsx")
#data converted to data frame
pen2 <- as.data.frame(peng2)

2. Check for missing values in the dataset. For any missing value(s) in a numeric column(s) of data, impute the average of the column.

sum(is.na(peng2))
## [1] 8
#bill_length, bill_depth, flipper length, and body_mass each have 2 missing values
sapply(peng2, function(x) sum(is.na(x)))
##           species            island    bill_length_mm     bill_depth_mm 
##                 0                 0                 2                 2 
## flipper_length_mm       body_mass_g              year 
##                 2                 2                 0
#Below missing values are imputed with the mean value and the last line of code shows no missing values left
peng2$bill_length_mm[is.na(peng2$bill_length_mm)] <- mean(peng2$bill_length_mm, na.rm = T)
peng2$bill_depth_mm[is.na(peng2$bill_depth_mm)] <- mean(peng2$bill_depth_mm, na.rm = T)
peng2$flipper_length_mm[is.na(peng2$flipper_length_mm)] <- mean(peng2$flipper_length_mm, na.rm = T)
peng2$body_mass_g[is.na(peng2$body_mass_g)] <- mean(peng2$body_mass_g, na.rm = T)
sum(is.na(peng2))
## [1] 0

3. Convert all non-numeric columns of data into factors.

str(peng2) # species and island are character columns and will be converted into factor columns
## tibble [344 × 7] (S3: tbl_df/tbl/data.frame)
##  $ species          : chr [1:344] "Adelie" "Adelie" "Adelie" "Adelie" ...
##  $ island           : chr [1:344] "Torgersen" "Torgersen" "Torgersen" "Torgersen" ...
##  $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 43.9 36.7 ...
##  $ bill_depth_mm    : num [1:344] 18.7 17.4 18 17.2 19.3 ...
##  $ flipper_length_mm: num [1:344] 181 186 195 201 193 ...
##  $ body_mass_g      : num [1:344] 3750 3800 3250 4202 3450 ...
##  $ year             : num [1:344] 2007 2007 2007 2007 2007 ...
peng2$species <- as.factor(peng2$species)
peng2$island <- as.factor(peng2$island)
str(peng2)
## tibble [344 × 7] (S3: tbl_df/tbl/data.frame)
##  $ species          : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ island           : Factor w/ 3 levels "Biscoe","Dream",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 43.9 36.7 ...
##  $ bill_depth_mm    : num [1:344] 18.7 17.4 18 17.2 19.3 ...
##  $ flipper_length_mm: num [1:344] 181 186 195 201 193 ...
##  $ body_mass_g      : num [1:344] 3750 3800 3250 4202 3450 ...
##  $ year             : num [1:344] 2007 2007 2007 2007 2007 ...

4. Randomly sample the rows of your data to include 90% of the rows in your training set. Use the rest of the rows as your testing set.

#90% of the peng2 data set is sampled below into the training set and the rest is put into the test set
index <- sample(nrow(peng2), nrow(peng2)*0.90)
peng2_train <- peng2[index,]
peng2_test <- peng2[-index,]

5. Using 10,000 trees that each have 3 splits, develop a boosting model to predict the body mass of a penguin. In creating your model, use a shrinkage/weight of 0.01.

library(gbm)
## Loaded gbm 2.1.8.1
#A boosting model using 10,000 trees with 3 splits and a shrinkage of 0.01
peng2_boost <- gbm(formula = body_mass_g~., data=peng2_train, distribution = "gaussian", n.trees = 10000, shrinkage = 0.01, interaction.depth = 3)

# the summary below shows the variables and their importance in both graph form and in a chart
summary(peng2_boost)

##                                 var  rel.inf
## flipper_length_mm flipper_length_mm 36.00890
## species                     species 22.35817
## bill_length_mm       bill_length_mm 18.20966
## bill_depth_mm         bill_depth_mm 17.80234
## island                       island  2.82837
## year                           year  2.79256

a) Does it make more sense to use the training set or testing set when developing this model? The training set b/c the model should be built on the training set to train the model and the predictions should be made on the testing set after the model is trained

b) Which covariate is most influential in your predictive model? In answering this question, be sure to provide your output from your code listing the relative influence of each covariate.

flipper_length_mm is the most influential covariate

###  See original printout below of each covariate from most influential at top with relative influence reported to the right of the variable

####  flipper_length_mm flipper_length_mm 39.217329
####  species                     species 20.161999
####  bill_length_mm       bill_length_mm 18.844067
####  bill_depth_mm         bill_depth_mm 16.139516
####  year                           year  2.826015
#### island                       island  2.811074

c) Create a graph displaying the relationship (as determined in your model) between the target variable and the most influential covariate.

# as flipper length increases so do the predictions
plot(peng2_boost, i = "flipper_length_mm")

d) Use the testing set to calculate your model’s mean squared error (MSE).

peng2_boost_pred_test <- predict(peng2_boost, peng2_test, n.trees = 10000)
mean((peng2_test$body_mass_g - peng2_boost_pred_test)^2)
## [1] 117497.7
#Original MSE calculate [1] 118,241.9

e) Create a graph displaying the test MSE when various amounts of trees are used in the boosting model. Based on this graph, could the MSE be improved by using a smaller number of trees? Be sure to provide the instructor with all output produced by your code.

ntree <- seq(100, 10000, 100)

peng2pred <- predict(peng2_boost, newdata = peng2_test, n.trees = ntree)
peng2pred
##            100      200      300      400      500      600      700      800
##  [1,] 3951.828 3843.371 3808.384 3790.930 3801.535 3803.437 3792.610 3788.591
##  [2,] 3866.554 3703.874 3630.289 3600.196 3604.217 3605.308 3596.470 3593.263
##  [3,] 3796.376 3617.104 3535.721 3513.173 3503.866 3519.360 3533.092 3538.799
##  [4,] 3728.215 3513.895 3402.977 3349.038 3315.792 3292.376 3286.125 3284.715
##  [5,] 3770.760 3630.259 3611.020 3623.914 3642.834 3660.012 3663.313 3674.023
##  [6,] 3897.119 3819.774 3828.231 3836.367 3846.622 3869.850 3879.867 3875.783
##  [7,] 3805.343 3613.889 3531.666 3497.598 3489.540 3485.066 3478.440 3483.557
##  [8,] 3910.293 3839.845 3823.144 3834.113 3841.690 3846.574 3835.186 3827.894
##  [9,] 3690.807 3433.176 3293.321 3214.664 3171.343 3138.032 3120.972 3113.099
## [10,] 4030.936 4045.792 4096.185 4138.005 4153.972 4175.002 4174.260 4171.234
## [11,] 3846.688 3736.156 3711.667 3719.746 3722.637 3721.761 3712.341 3709.025
## [12,] 3904.874 3840.434 3855.553 3873.821 3888.722 3902.894 3913.655 3910.958
## [13,] 3758.497 3520.289 3412.587 3363.900 3351.450 3337.035 3326.686 3318.084
## [14,] 3935.813 3796.941 3743.739 3714.324 3726.701 3736.202 3740.516 3735.467
## [15,] 3906.767 3815.457 3803.702 3819.232 3847.193 3879.245 3885.510 3890.343
## [16,] 4216.665 4267.608 4313.436 4330.622 4344.988 4372.603 4386.998 4387.198
## [17,] 3941.040 3886.820 3873.338 3864.934 3856.094 3866.181 3839.781 3830.687
## [18,] 3805.343 3608.962 3518.590 3473.046 3459.910 3448.103 3432.185 3432.883
## [19,] 5052.521 5387.633 5560.496 5649.275 5703.308 5734.211 5754.749 5775.069
## [20,] 4472.411 4524.030 4544.259 4543.723 4538.518 4528.600 4539.223 4525.467
## [21,] 4546.915 4673.399 4727.835 4746.970 4752.870 4748.736 4753.901 4744.772
## [22,] 4537.784 4645.991 4695.609 4721.495 4743.388 4748.681 4760.238 4764.740
## [23,] 4755.211 4963.102 5074.912 5106.419 5117.615 5126.160 5121.891 5120.994
## [24,] 4561.883 4688.271 4736.529 4746.748 4741.602 4737.209 4745.917 4733.001
## [25,] 4438.319 4483.418 4488.973 4471.470 4458.385 4444.166 4454.546 4439.832
## [26,] 5052.521 5381.005 5533.331 5595.695 5636.395 5660.353 5673.727 5684.942
## [27,] 5052.521 5381.656 5521.914 5583.340 5609.418 5620.345 5627.915 5638.380
## [28,] 4828.845 5057.051 5140.532 5154.337 5156.458 5150.633 5155.453 5148.432
## [29,] 4744.025 4979.971 5052.672 5086.412 5105.103 5117.369 5133.346 5145.962
## [30,] 3856.226 3725.543 3651.773 3627.067 3628.246 3617.990 3612.673 3600.753
## [31,] 4070.920 4023.545 4014.816 4027.791 4026.554 4024.999 4019.115 4012.283
## [32,] 3836.449 3670.839 3588.200 3557.129 3549.643 3537.189 3532.577 3530.723
## [33,] 3942.347 3851.985 3784.252 3746.052 3737.337 3732.186 3716.327 3702.983
## [34,] 3908.349 3784.603 3713.334 3669.254 3636.747 3625.514 3605.891 3607.523
## [35,] 3838.923 3672.643 3579.840 3539.955 3517.992 3503.355 3492.622 3486.385
##            900     1000     1100     1200     1300     1400     1500     1600
##  [1,] 3801.975 3808.795 3807.043 3817.149 3813.036 3809.033 3809.295 3802.878
##  [2,] 3593.014 3587.447 3569.825 3579.940 3576.545 3565.776 3555.058 3544.445
##  [3,] 3543.263 3542.241 3536.551 3540.877 3540.751 3542.595 3538.843 3533.135
##  [4,] 3281.701 3268.276 3262.613 3253.772 3257.899 3247.678 3236.253 3240.080
##  [5,] 3686.871 3696.347 3697.962 3703.052 3720.067 3721.547 3732.208 3727.385
##  [6,] 3875.479 3872.097 3881.054 3880.089 3876.797 3881.199 3878.677 3873.641
##  [7,] 3488.094 3488.339 3476.840 3485.277 3486.971 3490.256 3482.654 3474.824
##  [8,] 3816.914 3811.544 3799.382 3794.964 3781.444 3784.016 3771.371 3759.855
##  [9,] 3113.072 3091.497 3080.693 3082.053 3081.441 3076.927 3062.334 3053.817
## [10,] 4169.869 4176.684 4181.135 4186.565 4174.528 4180.205 4168.988 4169.075
## [11,] 3700.914 3702.126 3691.793 3691.099 3680.319 3681.102 3665.484 3650.619
## [12,] 3906.472 3909.092 3909.913 3912.136 3908.530 3911.100 3907.796 3903.028
## [13,] 3325.881 3318.777 3310.395 3318.317 3324.106 3323.229 3322.365 3319.737
## [14,] 3753.772 3752.963 3752.880 3759.756 3761.459 3766.183 3769.642 3772.726
## [15,] 3893.276 3902.893 3904.322 3907.010 3904.885 3912.478 3914.131 3911.619
## [16,] 4392.178 4396.682 4402.914 4415.867 4405.606 4417.935 4414.324 4420.613
## [17,] 3820.471 3814.819 3808.126 3806.800 3789.599 3784.748 3766.822 3761.057
## [18,] 3438.192 3436.196 3427.035 3440.069 3443.303 3446.263 3448.369 3448.124
## [19,] 5776.992 5788.546 5797.456 5805.315 5814.561 5813.157 5820.221 5829.464
## [20,] 4524.599 4528.306 4527.851 4529.709 4527.635 4533.841 4525.732 4524.625
## [21,] 4747.487 4743.566 4748.017 4743.840 4741.061 4743.287 4739.470 4733.591
## [22,] 4770.671 4773.370 4778.894 4783.435 4783.499 4787.487 4782.993 4780.623
## [23,] 5108.249 5108.021 5103.483 5101.644 5106.429 5102.126 5101.455 5098.555
## [24,] 4735.055 4744.800 4753.682 4754.042 4753.269 4757.500 4743.549 4738.247
## [25,] 4435.179 4435.635 4443.922 4445.021 4442.724 4453.917 4445.070 4446.935
## [26,] 5682.943 5685.032 5689.896 5690.045 5687.430 5683.108 5690.890 5692.515
## [27,] 5643.269 5645.653 5652.725 5639.270 5644.318 5641.372 5652.018 5640.186
## [28,] 5139.814 5139.712 5140.074 5148.174 5146.656 5139.034 5139.907 5142.837
## [29,] 5149.633 5152.106 5159.087 5162.260 5160.059 5167.918 5171.329 5175.153
## [30,] 3602.901 3588.700 3590.025 3578.396 3578.788 3572.182 3568.829 3555.860
## [31,] 4020.674 4029.396 4029.827 4027.389 4031.226 4024.245 4024.416 4015.308
## [32,] 3533.300 3526.553 3522.308 3512.295 3514.174 3513.319 3516.218 3510.603
## [33,] 3698.342 3687.977 3689.855 3681.622 3675.977 3662.479 3666.604 3659.983
## [34,] 3603.681 3600.110 3602.171 3594.712 3597.458 3583.108 3587.905 3576.868
## [35,] 3487.230 3484.457 3485.260 3478.040 3481.991 3482.828 3488.836 3486.730
##           1700     1800     1900     2000     2100     2200     2300     2400
##  [1,] 3800.701 3813.017 3809.325 3811.135 3811.906 3821.099 3818.319 3829.002
##  [2,] 3535.786 3538.913 3534.185 3531.334 3537.099 3533.074 3541.037 3541.876
##  [3,] 3526.808 3524.253 3526.382 3529.142 3536.764 3529.027 3541.662 3538.465
##  [4,] 3234.255 3222.752 3218.722 3211.428 3210.872 3199.183 3197.654 3190.362
##  [5,] 3726.881 3727.369 3739.324 3737.750 3743.156 3748.790 3747.250 3742.655
##  [6,] 3876.825 3881.428 3884.034 3878.515 3886.203 3886.647 3882.654 3887.959
##  [7,] 3472.093 3474.558 3473.625 3473.688 3483.389 3477.106 3477.543 3472.772
##  [8,] 3752.963 3752.787 3749.858 3742.265 3742.462 3743.188 3734.464 3733.045
##  [9,] 3045.874 3034.650 3032.699 3023.340 3020.509 3013.800 3008.165 3000.438
## [10,] 4166.953 4168.264 4160.169 4152.176 4150.851 4149.655 4144.377 4147.570
## [11,] 3648.797 3642.111 3638.190 3632.656 3629.749 3622.865 3620.697 3620.819
## [12,] 3905.233 3914.302 3912.978 3905.914 3905.721 3903.854 3898.387 3900.419
## [13,] 3321.749 3319.797 3324.213 3323.120 3328.966 3332.897 3334.582 3333.458
## [14,] 3773.191 3785.397 3789.149 3799.938 3809.517 3816.879 3818.581 3822.826
## [15,] 3907.487 3910.857 3920.181 3919.544 3922.316 3927.869 3923.660 3932.530
## [16,] 4430.358 4437.602 4438.513 4444.579 4447.458 4451.786 4451.898 4454.362
## [17,] 3751.282 3749.082 3741.606 3734.886 3727.835 3724.620 3719.632 3727.216
## [18,] 3447.152 3453.917 3446.354 3448.658 3451.546 3459.219 3462.285 3463.998
## [19,] 5833.337 5843.067 5854.050 5858.598 5864.008 5859.316 5871.355 5870.378
## [20,] 4527.965 4528.729 4523.928 4528.101 4532.342 4528.840 4526.173 4526.180
## [21,] 4727.591 4737.708 4726.995 4727.444 4725.212 4730.133 4727.645 4734.293
## [22,] 4778.285 4775.449 4765.926 4769.144 4763.456 4769.766 4762.954 4764.958
## [23,] 5101.993 5107.608 5110.343 5116.098 5113.741 5112.950 5130.371 5130.485
## [24,] 4742.451 4752.078 4749.393 4753.044 4761.623 4763.018 4764.193 4771.721
## [25,] 4455.276 4462.518 4464.772 4470.024 4476.676 4477.541 4476.370 4483.726
## [26,] 5696.078 5703.066 5706.716 5710.818 5708.444 5699.620 5711.484 5711.050
## [27,] 5632.823 5636.486 5638.826 5642.773 5642.455 5632.475 5634.183 5636.043
## [28,] 5149.626 5158.637 5167.962 5174.124 5167.299 5170.350 5173.488 5183.121
## [29,] 5174.422 5181.828 5189.024 5194.165 5188.557 5193.562 5192.007 5193.488
## [30,] 3570.259 3571.946 3576.080 3575.946 3581.354 3585.054 3574.464 3572.678
## [31,] 4017.946 4029.590 4033.936 4026.538 4020.224 4023.004 4009.881 4007.851
## [32,] 3512.499 3507.141 3506.958 3507.748 3516.353 3517.519 3523.117 3520.247
## [33,] 3665.826 3663.167 3661.690 3664.626 3663.545 3664.116 3661.909 3667.653
## [34,] 3565.888 3560.999 3559.830 3548.952 3551.523 3544.181 3543.957 3545.510
## [35,] 3489.189 3484.191 3479.713 3481.784 3487.124 3487.630 3492.824 3494.671
##           2500     2600     2700     2800     2900     3000     3100     3200
##  [1,] 3834.576 3837.252 3841.743 3836.502 3845.763 3857.099 3859.021 3853.091
##  [2,] 3538.114 3533.966 3543.321 3541.787 3538.785 3554.657 3557.517 3548.753
##  [3,] 3539.121 3530.496 3533.735 3531.184 3527.361 3537.269 3545.270 3549.253
##  [4,] 3176.971 3170.034 3164.733 3160.946 3161.868 3168.674 3169.744 3170.698
##  [5,] 3740.174 3737.799 3728.440 3731.611 3728.383 3733.138 3741.204 3732.674
##  [6,] 3890.458 3877.234 3863.541 3865.864 3859.660 3867.665 3877.124 3882.916
##  [7,] 3467.729 3464.797 3462.023 3471.367 3462.050 3478.428 3483.694 3480.192
##  [8,] 3731.780 3724.248 3725.586 3718.208 3713.226 3716.420 3717.659 3714.731
##  [9,] 2994.607 2991.320 2987.473 2992.336 2982.874 2989.138 2991.232 2989.456
## [10,] 4156.135 4161.833 4149.273 4141.727 4144.243 4138.386 4148.266 4146.391
## [11,] 3614.176 3603.612 3602.857 3593.965 3588.271 3592.246 3593.349 3587.501
## [12,] 3908.612 3899.304 3885.535 3884.083 3879.536 3885.062 3891.379 3896.096
## [13,] 3330.395 3334.531 3329.739 3340.621 3334.889 3342.100 3342.066 3344.155
## [14,] 3828.010 3822.400 3830.473 3838.900 3839.191 3852.517 3855.768 3857.805
## [15,] 3927.341 3915.419 3916.609 3918.588 3915.759 3916.460 3917.815 3917.122
## [16,] 4458.603 4455.051 4466.526 4469.462 4476.499 4473.340 4479.389 4487.913
## [17,] 3723.783 3719.275 3727.359 3714.548 3709.044 3694.421 3692.381 3689.510
## [18,] 3461.958 3466.317 3467.862 3475.167 3475.716 3481.623 3488.541 3481.654
## [19,] 5871.861 5866.638 5870.567 5872.952 5875.126 5879.096 5885.162 5887.388
## [20,] 4526.858 4521.020 4529.246 4527.035 4529.525 4528.344 4529.376 4519.545
## [21,] 4736.614 4733.198 4742.010 4738.040 4737.903 4738.133 4739.347 4728.402
## [22,] 4761.595 4756.189 4764.439 4761.673 4759.909 4761.008 4760.877 4758.154
## [23,] 5142.345 5144.875 5151.002 5152.544 5143.940 5140.206 5145.973 5142.342
## [24,] 4775.350 4775.817 4784.306 4787.895 4791.749 4792.537 4789.051 4782.717
## [25,] 4493.742 4489.839 4498.360 4499.758 4499.990 4500.719 4505.538 4499.436
## [26,] 5709.522 5704.316 5706.245 5710.085 5703.739 5699.834 5705.201 5710.192
## [27,] 5633.822 5630.220 5634.488 5640.359 5636.475 5630.518 5637.610 5634.468
## [28,] 5184.206 5182.225 5181.832 5188.360 5193.684 5195.018 5197.083 5210.957
## [29,] 5195.285 5197.536 5201.617 5208.684 5211.342 5219.480 5218.343 5223.051
## [30,] 3566.865 3563.242 3556.546 3549.342 3546.565 3549.578 3554.146 3547.307
## [31,] 4006.177 4007.820 4005.533 4011.419 4018.733 4009.992 4008.212 4010.053
## [32,] 3518.147 3521.846 3520.145 3515.091 3517.623 3524.995 3526.265 3515.903
## [33,] 3668.051 3665.137 3670.708 3666.358 3659.960 3658.698 3659.481 3656.391
## [34,] 3545.926 3549.338 3543.931 3542.670 3540.949 3544.303 3550.345 3545.686
## [35,] 3489.979 3498.746 3498.900 3494.224 3497.573 3504.908 3505.554 3499.923
##           3300     3400     3500     3600     3700     3800     3900     4000
##  [1,] 3855.671 3858.698 3864.523 3864.297 3864.149 3872.570 3878.481 3882.626
##  [2,] 3551.106 3553.130 3553.886 3548.088 3542.868 3541.581 3551.829 3547.692
##  [3,] 3550.676 3542.307 3551.506 3549.955 3545.879 3562.106 3558.509 3556.040
##  [4,] 3169.972 3165.229 3166.980 3166.350 3160.248 3176.423 3166.615 3164.116
##  [5,] 3734.966 3738.001 3740.731 3747.591 3749.240 3751.506 3749.622 3742.879
##  [6,] 3875.951 3872.986 3879.878 3879.814 3880.084 3886.345 3881.886 3881.607
##  [7,] 3477.383 3478.787 3477.401 3482.106 3475.116 3471.026 3474.916 3473.195
##  [8,] 3709.960 3698.847 3698.257 3696.826 3694.369 3694.202 3688.618 3684.619
##  [9,] 2976.871 2975.772 2974.718 2972.254 2970.402 2975.926 2971.499 2966.606
## [10,] 4142.937 4145.918 4144.435 4143.102 4142.209 4144.385 4133.980 4140.597
## [11,] 3581.661 3574.321 3578.092 3581.865 3580.396 3580.499 3577.601 3569.146
## [12,] 3893.440 3892.449 3893.604 3897.103 3893.678 3898.115 3887.212 3890.631
## [13,] 3339.203 3346.268 3341.948 3334.380 3329.658 3329.696 3338.098 3338.716
## [14,] 3859.270 3863.824 3863.584 3865.735 3859.141 3864.574 3879.074 3884.224
## [15,] 3912.868 3909.484 3911.753 3911.303 3911.126 3909.193 3913.322 3907.856
## [16,] 4486.884 4491.368 4495.755 4497.014 4508.033 4508.333 4510.159 4512.158
## [17,] 3674.947 3666.302 3657.408 3654.783 3652.596 3641.417 3637.252 3632.590
## [18,] 3478.912 3489.012 3489.667 3491.070 3493.202 3493.656 3499.621 3499.970
## [19,] 5896.397 5897.461 5896.556 5899.771 5905.095 5911.961 5905.034 5906.467
## [20,] 4516.851 4520.250 4523.399 4518.994 4512.703 4521.409 4521.473 4519.325
## [21,] 4729.406 4727.019 4728.529 4728.219 4731.139 4735.651 4729.675 4720.210
## [22,] 4757.196 4756.074 4757.887 4750.204 4752.821 4757.700 4758.380 4750.667
## [23,] 5153.626 5152.956 5149.898 5153.508 5169.154 5172.420 5166.845 5161.051
## [24,] 4784.045 4787.405 4793.483 4792.928 4795.598 4807.086 4802.470 4797.620
## [25,] 4496.010 4499.684 4502.934 4503.294 4499.691 4505.610 4511.849 4510.216
## [26,] 5716.788 5721.254 5722.553 5725.269 5726.116 5725.481 5721.413 5722.110
## [27,] 5634.483 5633.173 5634.149 5630.649 5631.670 5630.215 5628.407 5626.560
## [28,] 5211.543 5213.618 5216.173 5213.731 5213.640 5212.542 5219.990 5219.011
## [29,] 5219.919 5223.953 5224.146 5219.895 5224.847 5232.760 5238.772 5243.110
## [30,] 3550.943 3545.092 3541.108 3541.415 3542.392 3542.032 3537.828 3536.033
## [31,] 4012.470 4016.417 4007.909 4006.026 4013.987 4011.987 4011.785 4015.041
## [32,] 3510.840 3505.019 3504.437 3506.715 3511.616 3506.482 3511.587 3507.560
## [33,] 3656.597 3655.129 3649.030 3651.758 3656.373 3643.550 3647.598 3647.125
## [34,] 3541.393 3543.006 3528.929 3532.524 3535.766 3524.661 3532.501 3525.124
## [35,] 3496.847 3498.355 3503.824 3509.970 3512.382 3510.252 3509.234 3506.539
##           4100     4200     4300     4400     4500     4600     4700     4800
##  [1,] 3886.434 3880.479 3886.618 3895.919 3890.284 3899.902 3908.416 3907.597
##  [2,] 3548.861 3548.192 3556.712 3558.285 3553.112 3556.564 3559.163 3556.998
##  [3,] 3553.065 3554.792 3560.144 3564.568 3561.200 3564.927 3569.695 3568.841
##  [4,] 3164.384 3156.455 3158.333 3158.108 3154.578 3162.230 3162.640 3160.415
##  [5,] 3748.279 3744.881 3740.261 3743.630 3748.592 3756.205 3755.271 3747.486
##  [6,] 3881.876 3882.501 3875.711 3876.688 3871.187 3872.890 3868.771 3873.288
##  [7,] 3472.144 3475.122 3486.960 3491.402 3482.917 3483.875 3489.859 3494.214
##  [8,] 3683.505 3694.450 3689.942 3684.403 3686.430 3683.732 3679.884 3682.446
##  [9,] 2967.278 2960.216 2964.349 2969.861 2962.352 2964.140 2960.512 2962.986
## [10,] 4134.051 4141.356 4141.707 4139.544 4139.301 4136.875 4130.012 4126.488
## [11,] 3566.723 3572.412 3571.323 3564.985 3572.181 3574.333 3566.079 3564.639
## [12,] 3890.609 3896.345 3893.719 3896.623 3895.028 3891.116 3890.293 3893.153
## [13,] 3344.817 3338.962 3353.449 3359.648 3351.325 3354.578 3352.659 3353.427
## [14,] 3891.843 3885.723 3894.656 3901.618 3894.955 3901.875 3907.169 3910.682
## [15,] 3915.735 3910.869 3903.908 3907.015 3908.267 3911.727 3903.861 3904.502
## [16,] 4522.390 4525.883 4525.976 4525.057 4522.147 4520.895 4526.289 4533.882
## [17,] 3635.058 3634.553 3629.740 3617.639 3616.319 3611.245 3599.125 3596.838
## [18,] 3507.226 3508.857 3514.901 3516.621 3511.242 3507.362 3511.064 3511.188
## [19,] 5904.632 5910.003 5908.616 5910.937 5921.272 5924.731 5919.354 5927.635
## [20,] 4521.467 4524.809 4526.765 4518.841 4520.347 4517.731 4520.911 4521.093
## [21,] 4726.312 4729.020 4725.833 4721.103 4719.370 4723.872 4724.669 4724.989
## [22,] 4757.453 4753.572 4755.003 4751.382 4755.534 4750.057 4748.558 4749.689
## [23,] 5160.013 5171.454 5168.438 5159.816 5162.145 5163.486 5158.848 5166.345
## [24,] 4802.582 4811.798 4812.979 4810.628 4808.330 4818.623 4822.184 4822.862
## [25,] 4510.888 4515.344 4521.949 4519.879 4523.429 4523.975 4526.222 4527.970
## [26,] 5717.589 5718.505 5721.080 5719.713 5730.331 5733.811 5731.283 5735.382
## [27,] 5624.105 5620.664 5622.288 5618.999 5624.412 5621.562 5620.603 5623.674
## [28,] 5216.105 5215.340 5224.780 5216.333 5228.845 5227.821 5220.395 5224.713
## [29,] 5244.586 5247.931 5253.663 5254.301 5258.903 5257.359 5258.639 5262.423
## [30,] 3539.049 3539.113 3535.193 3539.097 3544.203 3536.754 3534.468 3538.180
## [31,] 4012.742 4010.567 4010.179 4021.154 4026.134 4025.068 4029.003 4025.086
## [32,] 3512.211 3514.260 3515.807 3506.217 3513.292 3508.938 3503.816 3506.419
## [33,] 3650.911 3656.449 3653.540 3645.738 3649.437 3645.757 3637.865 3636.458
## [34,] 3522.093 3520.211 3516.960 3511.908 3507.646 3502.320 3493.837 3493.514
## [35,] 3507.840 3506.966 3509.233 3503.886 3507.041 3498.592 3490.212 3491.019
##           4900     5000     5100     5200     5300     5400     5500     5600
##  [1,] 3911.179 3912.127 3909.930 3915.493 3906.615 3920.308 3916.252 3907.070
##  [2,] 3558.796 3555.005 3549.915 3554.087 3548.339 3556.074 3554.769 3547.193
##  [3,] 3571.888 3571.018 3572.646 3572.568 3573.162 3572.505 3575.298 3574.347
##  [4,] 3157.664 3155.030 3155.299 3158.562 3159.043 3148.231 3145.790 3152.288
##  [5,] 3748.061 3740.932 3745.021 3745.187 3746.724 3749.788 3749.107 3755.914
##  [6,] 3876.481 3875.139 3877.935 3876.703 3869.725 3876.573 3871.156 3876.722
##  [7,] 3497.664 3494.212 3491.260 3497.688 3493.498 3502.325 3504.117 3503.213
##  [8,] 3680.073 3680.384 3679.129 3676.780 3675.596 3679.681 3678.680 3678.006
##  [9,] 2962.230 2965.864 2960.098 2967.248 2965.246 2960.087 2954.355 2960.468
## [10,] 4123.391 4129.275 4128.754 4120.063 4122.812 4122.253 4120.077 4123.951
## [11,] 3562.885 3566.348 3566.025 3566.271 3559.580 3561.827 3564.358 3566.991
## [12,] 3895.861 3896.873 3896.180 3892.745 3888.187 3892.678 3887.082 3886.809
## [13,] 3357.100 3354.113 3347.964 3355.141 3355.300 3364.574 3358.407 3357.714
## [14,] 3916.570 3916.960 3912.105 3918.731 3913.992 3926.991 3925.515 3920.354
## [15,] 3900.073 3893.333 3891.909 3893.032 3894.298 3902.487 3902.678 3907.227
## [16,] 4534.465 4528.243 4538.137 4537.701 4539.212 4544.706 4540.924 4538.749
## [17,] 3587.710 3584.540 3584.097 3573.213 3569.979 3575.143 3569.262 3573.504
## [18,] 3508.620 3507.069 3502.220 3506.211 3505.654 3509.541 3502.286 3501.694
## [19,] 5917.092 5914.378 5920.014 5914.546 5925.887 5925.149 5929.350 5923.278
## [20,] 4516.566 4516.990 4516.171 4519.534 4520.692 4525.608 4522.224 4522.663
## [21,] 4719.148 4716.665 4722.639 4724.495 4720.221 4724.276 4724.663 4723.928
## [22,] 4753.778 4751.298 4749.594 4750.256 4750.880 4751.750 4749.644 4746.082
## [23,] 5158.901 5157.076 5155.222 5152.261 5154.235 5158.346 5163.890 5168.423
## [24,] 4816.966 4816.034 4822.419 4830.289 4826.876 4831.578 4835.439 4839.449
## [25,] 4523.420 4526.720 4529.800 4536.387 4540.489 4544.372 4543.990 4547.035
## [26,] 5725.166 5723.443 5728.176 5724.476 5732.056 5730.819 5733.578 5731.445
## [27,] 5621.956 5617.497 5618.085 5616.654 5624.003 5625.991 5622.770 5621.563
## [28,] 5223.020 5221.772 5223.688 5229.416 5227.387 5223.153 5225.924 5222.117
## [29,] 5264.217 5261.697 5267.222 5271.161 5278.446 5279.150 5283.066 5287.718
## [30,] 3541.444 3532.990 3532.622 3533.813 3531.989 3535.690 3530.952 3522.925
## [31,] 4030.859 4033.423 4025.843 4025.689 4031.668 4038.713 4037.417 4032.951
## [32,] 3512.802 3511.953 3512.005 3512.868 3513.452 3513.461 3511.939 3514.404
## [33,] 3639.189 3635.386 3634.506 3631.932 3638.474 3645.093 3641.135 3643.052
## [34,] 3497.052 3496.342 3494.445 3493.633 3495.470 3494.393 3486.703 3486.730
## [35,] 3498.315 3497.366 3494.782 3498.015 3493.642 3495.122 3489.411 3487.433
##           5700     5800     5900     6000     6100     6200     6300     6400
##  [1,] 3907.786 3912.763 3918.360 3911.866 3916.841 3920.871 3923.056 3924.067
##  [2,] 3546.754 3558.663 3565.360 3559.862 3564.222 3568.425 3568.046 3569.471
##  [3,] 3571.949 3579.893 3574.032 3578.188 3580.920 3584.695 3580.886 3578.900
##  [4,] 3154.180 3152.521 3146.090 3149.121 3145.458 3145.231 3143.220 3141.189
##  [5,] 3762.138 3758.630 3756.263 3761.629 3761.348 3760.645 3760.224 3765.943
##  [6,] 3882.101 3881.145 3879.691 3877.414 3880.937 3882.088 3881.829 3878.747
##  [7,] 3502.303 3512.276 3514.498 3508.990 3505.478 3501.513 3500.975 3500.252
##  [8,] 3677.910 3682.157 3679.878 3679.160 3677.878 3676.244 3673.023 3665.643
##  [9,] 2964.398 2965.347 2958.153 2963.221 2964.425 2955.567 2955.433 2956.117
## [10,] 4127.864 4132.234 4134.350 4129.568 4136.548 4134.425 4137.394 4133.428
## [11,] 3566.288 3571.494 3575.387 3576.864 3577.349 3577.715 3577.756 3573.284
## [12,] 3893.584 3898.997 3901.710 3901.115 3907.277 3906.722 3911.575 3907.382
## [13,] 3358.152 3363.488 3374.285 3369.367 3372.381 3369.376 3365.241 3367.785
## [14,] 3928.467 3934.889 3938.267 3937.065 3941.875 3944.532 3942.581 3942.616
## [15,] 3904.892 3903.153 3899.547 3901.530 3905.446 3904.610 3899.933 3902.503
## [16,] 4536.376 4538.381 4538.681 4540.497 4542.103 4543.465 4541.620 4543.568
## [17,] 3568.763 3560.109 3558.663 3554.300 3552.088 3547.737 3544.546 3538.780
## [18,] 3502.745 3506.807 3515.400 3513.455 3520.695 3514.663 3511.440 3516.763
## [19,] 5925.788 5918.384 5921.736 5922.764 5918.932 5919.181 5927.934 5929.751
## [20,] 4519.475 4515.590 4513.677 4515.903 4513.058 4509.380 4512.766 4514.404
## [21,] 4721.038 4722.414 4718.888 4717.479 4715.941 4717.781 4717.664 4717.101
## [22,] 4745.124 4748.261 4745.763 4751.286 4745.790 4747.148 4750.733 4747.546
## [23,] 5163.695 5162.684 5168.177 5167.283 5161.237 5164.122 5169.759 5163.337
## [24,] 4837.346 4836.993 4834.492 4839.140 4839.297 4835.660 4836.391 4837.667
## [25,] 4543.708 4542.199 4542.048 4545.439 4545.537 4544.812 4544.117 4547.365
## [26,] 5734.722 5729.459 5735.694 5730.834 5730.260 5728.174 5733.506 5733.601
## [27,] 5618.389 5613.274 5620.967 5620.278 5622.956 5621.163 5617.094 5618.800
## [28,] 5224.016 5228.184 5229.111 5231.627 5227.980 5229.983 5237.794 5238.954
## [29,] 5284.528 5293.163 5298.787 5304.066 5308.242 5305.444 5299.321 5302.158
## [30,] 3531.244 3531.902 3528.879 3529.197 3528.918 3533.811 3531.026 3528.509
## [31,] 4034.248 4038.256 4036.714 4040.070 4036.165 4038.911 4039.401 4041.753
## [32,] 3516.258 3520.960 3523.699 3527.290 3522.394 3524.637 3519.250 3518.588
## [33,] 3650.550 3647.096 3644.053 3638.392 3637.672 3641.447 3642.273 3639.080
## [34,] 3480.357 3476.554 3475.882 3472.829 3472.715 3473.037 3465.305 3468.280
## [35,] 3490.326 3495.444 3498.306 3498.211 3495.694 3500.034 3498.176 3500.241
##           6500     6600     6700     6800     6900     7000     7100     7200
##  [1,] 3928.555 3936.607 3941.323 3942.510 3943.018 3949.164 3951.754 3958.209
##  [2,] 3573.145 3573.174 3580.864 3577.473 3575.682 3572.011 3568.947 3570.956
##  [3,] 3576.524 3577.983 3581.041 3575.629 3577.992 3579.109 3577.704 3576.724
##  [4,] 3141.823 3144.965 3143.532 3135.638 3136.905 3132.546 3136.500 3129.538
##  [5,] 3763.089 3763.525 3760.963 3758.152 3765.299 3761.658 3761.601 3760.612
##  [6,] 3874.128 3875.989 3872.871 3872.748 3872.931 3874.843 3872.071 3868.669
##  [7,] 3496.258 3495.854 3499.403 3498.633 3495.065 3496.647 3494.063 3495.979
##  [8,] 3664.543 3664.940 3658.810 3660.421 3657.653 3664.664 3660.490 3659.490
##  [9,] 2960.289 2967.314 2967.368 2966.679 2966.706 2971.015 2966.956 2967.370
## [10,] 4135.055 4133.247 4122.684 4127.171 4127.545 4132.787 4128.221 4128.431
## [11,] 3566.494 3566.112 3561.223 3560.759 3558.949 3563.428 3558.205 3559.040
## [12,] 3906.288 3908.575 3905.009 3909.030 3909.349 3914.079 3909.794 3912.093
## [13,] 3364.313 3361.722 3365.426 3360.558 3359.062 3356.576 3359.095 3361.823
## [14,] 3941.993 3943.938 3948.964 3949.629 3947.802 3946.817 3946.222 3950.197
## [15,] 3898.887 3899.999 3905.779 3902.813 3902.225 3904.734 3909.483 3911.565
## [16,] 4544.437 4550.887 4544.304 4550.434 4555.040 4557.719 4553.203 4549.513
## [17,] 3540.945 3530.212 3528.748 3521.686 3518.815 3522.055 3519.193 3522.600
## [18,] 3519.337 3515.833 3516.920 3517.692 3515.227 3517.339 3515.156 3516.008
## [19,] 5926.422 5931.800 5936.851 5931.472 5924.375 5920.564 5917.081 5921.691
## [20,] 4508.913 4509.028 4506.819 4505.240 4504.900 4500.404 4499.819 4501.987
## [21,] 4714.394 4715.814 4716.204 4714.851 4714.531 4711.443 4713.703 4716.783
## [22,] 4745.651 4750.404 4750.194 4748.371 4747.132 4739.675 4740.542 4744.057
## [23,] 5165.383 5167.720 5167.512 5167.129 5161.672 5157.735 5160.653 5168.031
## [24,] 4835.737 4837.077 4835.791 4838.115 4842.469 4838.510 4843.825 4847.163
## [25,] 4547.081 4546.922 4543.588 4547.478 4552.688 4554.915 4553.603 4553.694
## [26,] 5736.359 5742.401 5746.067 5744.357 5741.537 5743.314 5741.242 5744.174
## [27,] 5621.730 5620.726 5624.963 5621.438 5615.573 5618.688 5617.456 5618.044
## [28,] 5237.308 5240.605 5243.634 5243.326 5243.426 5242.205 5239.510 5243.304
## [29,] 5304.018 5305.871 5308.439 5302.716 5300.856 5304.500 5301.049 5303.106
## [30,] 3530.674 3525.819 3528.437 3525.261 3523.441 3527.090 3530.383 3527.719
## [31,] 4037.180 4031.525 4028.429 4030.680 4030.272 4033.738 4037.696 4036.154
## [32,] 3515.962 3515.004 3516.931 3519.418 3517.447 3522.533 3518.931 3516.423
## [33,] 3640.226 3635.169 3638.512 3641.839 3643.512 3648.218 3648.731 3644.919
## [34,] 3467.003 3457.211 3453.622 3449.238 3446.827 3448.643 3449.627 3451.121
## [35,] 3503.972 3502.358 3504.355 3505.678 3503.852 3508.139 3509.118 3508.736
##           7300     7400     7500     7600     7700     7800     7900     8000
##  [1,] 3954.319 3954.189 3953.690 3958.317 3955.225 3957.391 3952.663 3951.810
##  [2,] 3563.946 3569.848 3562.220 3564.224 3567.404 3566.724 3558.515 3556.210
##  [3,] 3574.355 3577.867 3578.529 3580.624 3583.109 3577.090 3574.553 3575.681
##  [4,] 3128.855 3130.667 3134.068 3132.234 3133.153 3125.337 3129.460 3126.823
##  [5,] 3766.611 3768.067 3769.344 3772.712 3771.671 3767.704 3765.196 3760.950
##  [6,] 3867.301 3865.818 3867.878 3872.668 3876.271 3873.398 3875.083 3872.161
##  [7,] 3486.778 3488.401 3486.670 3484.332 3488.148 3489.228 3483.198 3482.665
##  [8,] 3659.131 3662.051 3660.910 3660.559 3663.735 3665.374 3664.415 3660.117
##  [9,] 2960.993 2961.048 2965.877 2964.274 2964.005 2967.131 2964.458 2964.493
## [10,] 4131.820 4128.257 4120.064 4120.417 4122.703 4127.144 4129.563 4125.299
## [11,] 3556.562 3554.641 3550.390 3548.670 3547.256 3547.045 3545.596 3536.181
## [12,] 3914.139 3913.917 3911.078 3917.615 3918.850 3917.848 3918.815 3914.746
## [13,] 3356.043 3354.372 3352.528 3351.596 3352.958 3354.889 3350.858 3351.964
## [14,] 3939.021 3942.031 3941.388 3941.154 3948.690 3949.200 3943.538 3948.640
## [15,] 3909.276 3913.314 3915.224 3921.137 3917.453 3913.142 3912.958 3907.438
## [16,] 4547.737 4550.696 4554.123 4561.381 4559.537 4562.634 4564.355 4563.848
## [17,] 3517.622 3515.512 3509.493 3505.310 3505.196 3503.969 3497.502 3494.183
## [18,] 3508.744 3512.888 3511.288 3507.760 3510.165 3514.883 3516.843 3518.406
## [19,] 5916.299 5920.532 5923.125 5928.314 5927.384 5929.452 5929.151 5928.010
## [20,] 4511.200 4506.930 4507.327 4508.008 4509.078 4509.380 4508.894 4506.627
## [21,] 4721.532 4714.910 4713.613 4714.986 4712.405 4711.523 4712.777 4710.393
## [22,] 4744.287 4739.087 4745.348 4742.315 4746.298 4747.780 4755.675 4752.219
## [23,] 5162.891 5162.245 5166.614 5166.927 5164.018 5163.955 5166.359 5167.690
## [24,] 4855.783 4853.829 4852.662 4856.499 4854.919 4855.121 4856.493 4856.931
## [25,] 4561.382 4558.054 4557.401 4560.148 4560.151 4563.124 4560.317 4556.313
## [26,] 5743.051 5743.955 5746.089 5750.376 5750.713 5752.357 5749.163 5752.802
## [27,] 5621.157 5617.372 5620.427 5617.318 5613.366 5610.947 5612.274 5611.828
## [28,] 5248.822 5251.330 5251.784 5245.058 5244.952 5242.961 5246.810 5251.495
## [29,] 5304.650 5303.397 5307.484 5309.549 5315.473 5318.952 5321.347 5328.138
## [30,] 3525.988 3529.063 3526.982 3531.818 3535.510 3535.158 3537.848 3534.527
## [31,] 4038.306 4038.420 4038.397 4033.334 4035.338 4039.765 4040.723 4039.047
## [32,] 3511.481 3512.329 3512.192 3512.168 3512.729 3514.211 3514.095 3513.540
## [33,] 3640.784 3647.925 3647.943 3646.873 3648.587 3655.579 3653.033 3656.949
## [34,] 3446.890 3447.966 3446.876 3441.166 3440.630 3440.744 3436.634 3434.242
## [35,] 3503.533 3506.815 3504.465 3507.751 3508.729 3510.812 3512.466 3507.742
##           8100     8200     8300     8400     8500     8600     8700     8800
##  [1,] 3949.953 3956.972 3951.242 3955.349 3953.967 3954.297 3960.376 3962.706
##  [2,] 3555.445 3553.283 3547.609 3549.969 3555.992 3556.265 3558.410 3561.095
##  [3,] 3572.741 3578.265 3580.868 3579.438 3581.413 3579.685 3582.717 3583.031
##  [4,] 3128.991 3131.736 3130.618 3132.106 3133.575 3130.469 3139.684 3139.753
##  [5,] 3759.659 3764.760 3768.193 3767.489 3771.939 3775.007 3774.300 3773.269
##  [6,] 3872.825 3876.496 3875.809 3879.459 3880.809 3876.109 3872.120 3876.155
##  [7,] 3480.506 3481.876 3472.985 3475.983 3479.322 3478.548 3479.062 3478.981
##  [8,] 3664.251 3664.421 3667.119 3667.378 3665.957 3660.740 3658.390 3659.292
##  [9,] 2966.439 2973.121 2972.175 2977.942 2981.137 2977.019 2982.741 2981.739
## [10,] 4123.669 4121.406 4119.449 4123.242 4125.317 4127.356 4124.487 4125.337
## [11,] 3542.308 3538.308 3539.771 3541.780 3542.449 3538.366 3541.089 3543.785
## [12,] 3918.782 3921.687 3919.819 3921.798 3921.491 3917.668 3919.434 3921.515
## [13,] 3351.000 3349.061 3343.579 3345.963 3344.878 3347.003 3346.352 3342.541
## [14,] 3946.531 3948.517 3943.860 3949.462 3949.934 3949.454 3954.564 3957.170
## [15,] 3910.047 3910.337 3914.587 3917.100 3921.770 3921.013 3918.224 3920.305
## [16,] 4565.959 4563.197 4565.835 4567.772 4567.727 4563.778 4558.929 4560.795
## [17,] 3494.818 3490.053 3492.630 3490.812 3489.668 3489.778 3484.170 3483.558
## [18,] 3516.275 3515.956 3510.654 3514.444 3518.354 3519.343 3520.691 3519.222
## [19,] 5927.881 5925.906 5931.290 5927.533 5926.328 5924.384 5928.526 5922.680
## [20,] 4508.711 4508.104 4512.490 4509.962 4515.257 4515.128 4515.022 4519.686
## [21,] 4712.266 4705.517 4707.615 4703.764 4705.692 4703.695 4700.907 4698.625
## [22,] 4754.427 4749.550 4749.002 4750.195 4749.628 4750.599 4751.303 4749.717
## [23,] 5172.650 5171.266 5178.090 5171.927 5173.955 5175.667 5174.605 5173.708
## [24,] 4862.313 4861.351 4868.665 4867.749 4873.698 4874.598 4871.812 4873.811
## [25,] 4558.764 4558.931 4562.569 4562.794 4566.653 4570.869 4569.195 4573.738
## [26,] 5752.209 5749.558 5756.738 5756.891 5757.395 5750.218 5756.626 5750.129
## [27,] 5612.870 5611.270 5612.822 5612.171 5611.699 5610.314 5617.897 5612.461
## [28,] 5259.585 5260.888 5257.706 5259.354 5258.599 5251.990 5259.399 5257.125
## [29,] 5330.592 5328.986 5325.295 5325.834 5324.298 5327.342 5328.341 5327.869
## [30,] 3533.073 3530.530 3528.939 3532.571 3531.484 3534.564 3531.188 3531.280
## [31,] 4035.279 4035.128 4030.837 4036.979 4037.216 4044.698 4040.741 4044.233
## [32,] 3518.358 3515.473 3511.032 3520.728 3522.537 3518.170 3522.135 3520.725
## [33,] 3652.785 3652.760 3653.538 3653.772 3648.129 3649.204 3650.220 3651.741
## [34,] 3430.594 3426.017 3425.321 3429.041 3426.391 3429.868 3431.043 3427.618
## [35,] 3512.561 3506.957 3505.294 3507.704 3510.100 3514.366 3516.559 3512.960
##           8900     9000     9100     9200     9300     9400     9500     9600
##  [1,] 3963.949 3965.908 3967.353 3972.098 3973.240 3979.191 3974.763 3968.448
##  [2,] 3559.241 3559.106 3556.483 3561.880 3561.741 3565.274 3558.976 3553.951
##  [3,] 3578.049 3582.588 3587.051 3584.717 3585.226 3581.074 3582.258 3582.803
##  [4,] 3139.137 3141.363 3144.265 3144.975 3146.012 3141.531 3143.503 3143.217
##  [5,] 3774.318 3774.892 3776.189 3776.324 3769.682 3770.834 3769.541 3776.116
##  [6,] 3875.124 3878.016 3877.205 3878.032 3876.836 3876.104 3875.505 3879.383
##  [7,] 3476.091 3478.863 3475.169 3475.907 3477.973 3478.932 3472.958 3474.745
##  [8,] 3655.426 3654.982 3654.003 3650.535 3653.894 3652.320 3650.713 3649.305
##  [9,] 2979.957 2977.178 2975.457 2980.251 2982.791 2976.976 2980.389 2979.818
## [10,] 4121.261 4121.436 4124.714 4124.583 4125.331 4133.777 4132.065 4129.225
## [11,] 3537.814 3538.587 3539.294 3540.442 3539.621 3540.121 3536.053 3532.211
## [12,] 3920.642 3924.605 3923.885 3923.122 3924.209 3925.368 3925.584 3924.851
## [13,] 3343.180 3341.861 3338.098 3339.890 3339.174 3336.379 3330.421 3332.477
## [14,] 3955.184 3958.072 3956.635 3960.154 3964.632 3967.226 3964.350 3965.666
## [15,] 3919.772 3919.448 3922.824 3918.720 3917.392 3916.527 3912.657 3918.789
## [16,] 4562.822 4565.709 4569.473 4571.457 4571.789 4579.257 4576.935 4577.654
## [17,] 3476.819 3473.383 3467.524 3463.638 3463.236 3463.472 3458.545 3452.861
## [18,] 3516.581 3522.604 3520.239 3524.114 3521.078 3519.822 3520.278 3521.527
## [19,] 5923.909 5925.711 5923.615 5925.099 5925.392 5926.408 5930.355 5927.526
## [20,] 4516.798 4519.805 4520.359 4520.703 4520.412 4525.238 4519.577 4515.382
## [21,] 4697.290 4692.512 4688.522 4689.998 4689.796 4691.535 4688.348 4688.717
## [22,] 4751.741 4755.901 4751.172 4748.406 4749.128 4754.966 4748.580 4742.736
## [23,] 5168.307 5167.844 5163.931 5170.248 5170.569 5174.975 5175.701 5172.044
## [24,] 4869.852 4870.051 4869.611 4873.666 4874.766 4878.541 4873.502 4872.327
## [25,] 4570.507 4574.741 4577.066 4578.086 4576.074 4581.416 4575.490 4577.023
## [26,] 5751.924 5750.832 5751.189 5750.376 5751.768 5753.514 5755.729 5757.803
## [27,] 5615.845 5609.215 5608.076 5605.412 5608.661 5608.419 5609.308 5609.092
## [28,] 5263.092 5261.647 5263.908 5268.273 5268.639 5264.538 5259.636 5263.207
## [29,] 5330.225 5327.062 5334.277 5334.908 5335.107 5337.907 5336.684 5338.622
## [30,] 3532.643 3531.804 3531.880 3527.251 3533.803 3531.132 3532.228 3533.803
## [31,] 4046.700 4045.334 4047.383 4047.047 4044.811 4043.686 4042.847 4038.584
## [32,] 3520.734 3517.721 3522.368 3522.817 3521.798 3518.981 3516.573 3518.793
## [33,] 3649.734 3648.466 3653.170 3652.555 3653.472 3654.036 3655.228 3660.012
## [34,] 3428.540 3423.264 3422.797 3421.528 3418.158 3416.472 3412.746 3413.315
## [35,] 3510.851 3507.058 3511.879 3513.266 3511.827 3510.434 3508.801 3511.509
##           9700     9800     9900    10000
##  [1,] 3978.075 3976.672 3974.266 3975.897
##  [2,] 3555.888 3550.700 3548.913 3559.616
##  [3,] 3583.980 3580.050 3583.119 3590.322
##  [4,] 3137.499 3139.926 3137.431 3141.575
##  [5,] 3773.025 3770.760 3772.752 3776.561
##  [6,] 3875.819 3880.541 3881.775 3880.010
##  [7,] 3478.085 3478.505 3476.685 3482.870
##  [8,] 3649.778 3653.507 3657.978 3658.432
##  [9,] 2978.841 2980.305 2974.905 2970.854
## [10,] 4127.207 4124.131 4129.228 4132.801
## [11,] 3533.429 3532.536 3539.144 3543.400
## [12,] 3924.588 3930.068 3936.560 3937.291
## [13,] 3335.062 3335.129 3331.274 3332.515
## [14,] 3967.540 3972.915 3968.422 3967.691
## [15,] 3915.039 3917.649 3917.714 3919.344
## [16,] 4575.161 4578.885 4579.372 4577.990
## [17,] 3449.523 3447.161 3446.169 3450.370
## [18,] 3523.341 3524.339 3519.971 3525.508
## [19,] 5923.352 5923.186 5921.011 5919.001
## [20,] 4521.025 4518.950 4521.097 4520.538
## [21,] 4688.652 4683.857 4682.763 4676.354
## [22,] 4745.101 4738.640 4738.773 4738.127
## [23,] 5166.083 5162.550 5161.272 5169.454
## [24,] 4875.587 4875.496 4876.256 4873.569
## [25,] 4582.218 4579.737 4579.849 4577.689
## [26,] 5756.366 5759.526 5754.761 5750.409
## [27,] 5609.131 5617.435 5614.098 5608.275
## [28,] 5260.843 5263.211 5255.923 5259.478
## [29,] 5335.865 5344.619 5346.777 5343.518
## [30,] 3536.509 3532.398 3535.800 3533.862
## [31,] 4039.247 4034.961 4035.340 4034.257
## [32,] 3519.977 3517.548 3521.304 3520.846
## [33,] 3656.303 3651.747 3660.004 3660.094
## [34,] 3412.609 3409.117 3417.033 3416.784
## [35,] 3512.946 3511.468 3511.275 3512.588
dim(peng2pred)
## [1]  35 100
#[1]  35 100
peng2err <- apply((peng2pred-peng2_test$body_mass_g)^2, 2, mean)
plot(ntree, peng2err, type = 'l', col = 2, lwd = 2, xlab = "n.trees", ylab = "Test MSE")

#Yes the MSE could be improved by using at least less than 1000 trees according the graph

6. Now create a random forest of 10,000 trees to predict the body mass of a penguin. Be sure to provide the instructor with the output that you use to answer each part of this question below

library(randomForest)
## randomForest 4.7-1.1
## Type rfNews() to see new features/changes/bug fixes.
# random forest model built on peng2 data
peng2_rf <- randomForest(body_mass_g~., data=peng2_train, importance = TRUE, ntree = 10000)
peng2_rf
## 
## Call:
##  randomForest(formula = body_mass_g ~ ., data = peng2_train, importance = TRUE,      ntree = 10000) 
##                Type of random forest: regression
##                      Number of trees: 10000
## No. of variables tried at each split: 2
## 
##           Mean of squared residuals: 108752
##                     % Var explained: 83.02
#original output from model
#Mean of squared residuals: 107953.7
#% Var explained: 83.13

a) Based on the percent of variation explained by the model, do you believe that the randomforest fits your data well? Yes the percent of variation is 83% which is a good percentage of the model/data explained

b) What is the out-of-bag error for the random forest?

The out of bag error is the Mean of squared residuals: 107953.7 (calculated during first run)

c) What are the two most important covariates in your random forest model?

# variables of importance
peng2_rf$importance
##                      %IncMSE IncNodePurity
## species           380064.031      49530908
## island            110868.830      14975447
## bill_length_mm    103444.072      23521698
## bill_depth_mm     116059.426      37359452
## flipper_length_mm 350996.789      59001610
## year                4064.572       2361761
#Two most important covariates
# Species and flipper_length_mm

#Original chart

#                     %IncMSE IncNodePurity
#species           379380.379      49034660
#island            117536.646      15230163
#bill_length_mm    112345.491      24360894
#bill_depth_mm     117778.050      36546648
#flipper_length_mm 351685.723      58943069
#year                2724.914       2320621

d) Use the testing set to calculate the MSE for your random forest model. Based on your results, is the random forest more accurate than the boosting model? Or is your boosting model more accurate than your random forest?

peng2_rf_pred2 <- predict(peng2_rf, peng2_test)
mean((peng2_test$body_mass_g - peng2_rf_pred2)^2)
## [1] 85579.93
#Original MSE [1] 93,016.14

#The MSE for the boosting model is 118,241.9 which means the random forest model is more accurate since it has the lower MSE of 93,016.14

e) Create a graph comparing the out-of-bag error to the number of trees used in the random forest model. Based on this graph, does it appear that a large number of trees are needed to develop a fairly accurate random forest model?

#No, based on the graph below a lot of trees are not necessary (less than 1000)
plot(peng2_rf$mse, type = 'l', col = 2, lwd = 2, xlab = "ntree", ylab = "OOB Error")