This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
plot(cars)
library("vegan")
data("bird_Ohio")
Warning: data set ‘bird_Ohio’ not found
bird_Ohio
ncol(bird_Ohio)
[1] 48
sp.rich<-specnumber(bird_Ohio, MARGIN=1)
as.data.frame(sp.rich)
sp.even<-specnumber(bird_Ohio,MARGIN=2)
as.data.frame(sp.even)
shannon<-diversity(bird_Ohio, index = "shannon")
shannon
[1] 1.812353 2.443171 2.502177 2.449965 2.505759 2.508055
[7] 2.808416 2.632368 2.573988 2.450999 2.394499 2.670755
[13] 2.531704 2.538192 2.502138 2.671630 2.157016 2.003041
[19] 2.458384 2.517153 2.887236 2.238884 2.518361 2.459535
[25] 2.299249 2.324144 2.388357 2.443737 2.508801 2.239565
[31] 2.719239 2.669216 2.564513 2.220202 2.371608 2.728757
[37] 2.523222 2.698767 1.974502 2.403435 3.027143 2.929427
[43] 2.232029 2.326931 2.594871 2.428581 2.325057 1.853327
[49] 2.769102 2.504465 2.236733 2.948820 2.471493 2.608128
[55] 3.043401 2.600579 2.280595 2.117042 2.003623 2.829905
[61] 2.496714 2.873540 2.406037 2.131073 2.430766 2.713367
[67] 2.503175 2.517794 2.595210 2.233722 2.332257 2.371660
[73] 2.292052 2.391518 2.657784 2.475737 2.734494 2.356708
[79] 2.438921 2.292174 2.230160 2.444628 1.498985 2.542779
[85] 2.550645 2.736674 2.453161 2.339160 2.291078 2.258330
[91] 2.477123 2.602002 2.135238 2.001804 2.482235 2.668960
[97] 2.858335 2.649933 2.453522 2.865006 2.783952 2.998991
[103] 2.771560 2.295914 2.824489 2.383109 2.503965 2.634558
[109] 2.629183 2.519069 1.944464 2.445383 2.350606 2.406909
[115] 2.321891 2.375944 2.767400 2.843069 2.707323 2.148480
[121] 2.363373 2.489638 2.574951 2.517391 2.515402 2.707214
[127] 2.297690 2.547743 2.178186 2.640613 2.353198 2.386311
[133] 2.588825 2.240908 2.631116 3.003723 2.852913 2.490412
[139] 2.839435 2.716773 2.980252 2.197722 1.798709 2.885919
[145] 3.032903 2.485085 2.314192 2.241601 1.916081 2.567405
[151] 3.158537 2.891359 2.280094 2.767268 3.111523 2.444470
[157] 2.548230 2.518348 2.349092 2.625978 2.451639 2.764880
[163] 2.267142 3.161186 2.631644 2.692776 2.861356 2.906638
[169] 2.784373 2.308865 2.092852 2.622334 2.513477 2.282174
[175] 2.446827 2.388816 2.275937 2.354834 2.518677 2.193424
[181] 2.352495 2.779190 2.201542 2.549830 2.561493 2.912577
[187] 2.307692 2.637404 2.831398 2.850695 2.344426 2.665442
[193] 2.467880 2.850518 2.260180 2.756500 2.578963 2.309209
[199] 2.595555 2.466597 2.418257 2.351541 2.665416 1.990114
[205] 2.435551 2.375377 2.154783 2.893215 2.821822 2.495723
simpson<-diversity(bird_Ohio, index = "simpson")
simpson
[1] 0.7805326 0.8960000 0.9075255 0.8855556 0.9026709 0.9011446
[7] 0.9240237 0.9110302 0.9070295 0.8999270 0.8799049 0.9196694
[13] 0.8888889 0.8962500 0.9007561 0.9142661 0.8620038 0.8197531
[19] 0.8960302 0.9045369 0.9357639 0.8616864 0.8697979 0.8830796
[25] 0.8786848 0.8776042 0.8829630 0.8850442 0.8976082 0.8719723
[31] 0.9245578 0.9113564 0.9050365 0.8360000 0.8854685 0.9157440
[37] 0.8912000 0.9079717 0.8266667 0.8847737 0.9387269 0.9382716
[43] 0.8691650 0.8791308 0.9076543 0.8950000 0.8775000 0.7809917
[49] 0.9238683 0.8980229 0.8823143 0.9409722 0.8960459 0.9151874
[55] 0.9464575 0.9135355 0.8824142 0.8347107 0.8395062 0.9347352
[61] 0.9092971 0.9273192 0.8870523 0.8546384 0.8946281 0.9188345
[67] 0.8836806 0.8945578 0.9047852 0.8755556 0.8977778 0.8900227
[73] 0.8383743 0.8843537 0.9178994 0.8921324 0.9271163 0.8833792
[79] 0.8899955 0.8757396 0.8698061 0.8863772 0.7321429 0.9112500
[85] 0.9088757 0.9159111 0.8846154 0.8792000 0.8742791 0.8650765
[91] 0.9047619 0.9126276 0.8577610 0.8448118 0.9032922 0.9145881
[97] 0.9304734 0.9073433 0.8827977 0.9330652 0.9225839 0.9427660
[103] 0.9207786 0.8814879 0.9275148 0.8897929 0.8994646 0.9161111
[109] 0.9120708 0.9000000 0.7976000 0.8922902 0.8741319 0.8870392
[115] 0.8729339 0.8923182 0.9202477 0.9193787 0.9149520 0.8515625
[121] 0.8741497 0.8921324 0.9022485 0.9037901 0.8891293 0.9149338
[127] 0.8655500 0.8978052 0.8395062 0.9145408 0.8800000 0.8966837
[133] 0.9054134 0.8526786 0.9104132 0.9400889 0.9307670 0.8930664
[139] 0.9362500 0.9239452 0.9383673 0.8441358 0.7929240 0.9388889
[145] 0.9432398 0.8966667 0.8854644 0.8702422 0.8138013 0.9071220
[151] 0.9499541 0.9307195 0.8691716 0.9120499 0.9468599 0.8955442
[157] 0.8949804 0.9037901 0.8696377 0.9083176 0.8940972 0.9189189
[163] 0.8529779 0.9519312 0.9084298 0.9137329 0.9341564 0.9375000
[169] 0.9126658 0.8780992 0.8480726 0.9066607 0.8948148 0.8680556
[175] 0.8999082 0.8753463 0.8734995 0.8911565 0.8966667 0.8577610
[181] 0.8888889 0.9228395 0.8440083 0.9104540 0.9053498 0.9396386
[187] 0.8804283 0.9167658 0.9286332 0.9297778 0.8928200 0.9150327
[193] 0.8883929 0.9329660 0.8786848 0.9156283 0.9032922 0.8792867
[199] 0.9061250 0.8888889 0.8756378 0.8664554 0.9191176 0.8337950
[205] 0.8915289 0.8835063 0.8700000 0.9325017 0.9287965 0.8692904
invsimpson<-diversity(bird_Ohio, index = "invsimpson")
invsimpson
[1] 4.556485 9.615385 10.813793 8.737864 10.274419 10.115789
[7] 13.161994 11.239766 10.756098 9.992701 8.326733 12.448560
[13] 9.000000 9.638554 10.076190 11.664000 7.246575 5.547945
[19] 9.618182 10.475248 15.567568 7.229947 7.680365 8.552826
[25] 8.242991 8.170213 8.544304 8.698997 9.766404 7.810811
[31] 13.255172 11.281124 10.530364 6.097561 8.731225 11.868597
[37] 9.191176 10.866221 5.769231 8.678571 16.320388 16.200000
[43] 7.643216 8.273408 10.828877 9.523810 8.163265 4.566038
[49] 13.135135 9.806122 8.497207 16.941176 9.619632 11.790698
[55] 18.676768 11.565445 8.504425 6.050000 6.230769 15.322188
[61] 11.025000 13.758794 8.853659 6.879397 9.490196 12.320513
[67] 8.597015 9.483871 10.502564 8.035714 9.782609 9.092784
[73] 6.187135 8.647059 12.180180 9.270627 13.720497 8.574803
[79] 9.090535 8.047619 7.680851 8.801047 3.733333 11.267606
[85] 10.974026 11.892178 8.666667 8.278146 7.954128 7.411609
[91] 10.500000 11.445255 7.030418 6.443787 10.340426 11.707965
[97] 14.382979 10.792531 8.532258 14.939914 12.917211 17.472131
[103] 12.622857 8.437956 13.795918 9.073826 9.946746 11.920530
[109] 11.372781 10.000000 4.940711 9.284211 7.944828 8.852632
[115] 7.869919 9.286624 12.538824 12.403670 11.758065 6.736842
[121] 7.945946 9.270627 10.230024 10.393939 9.019512 11.755556
[127] 7.437710 9.785235 6.230769 11.701493 8.333333 9.679012
[133] 10.572327 6.787879 11.162362 16.691395 14.443983 9.351598
[139] 15.686275 13.148410 16.225166 6.415842 4.829146 16.363636
[145] 17.617978 9.677419 8.730909 7.706667 5.370607 10.766816
[151] 19.981651 14.434084 7.643599 11.370079 18.818182 9.573427
[157] 9.522034 10.393939 7.670927 10.907216 9.442623 12.333333
[163] 6.801700 20.803509 10.920578 11.591900 15.187500 16.000000
[169] 11.450262 8.203390 6.582090 10.713604 9.507042 7.578947
[175] 9.990826 8.022222 7.905109 9.187500 9.677419 7.030418
[181] 9.000000 12.960000 6.410596 11.167442 10.565217 16.566879
[187] 8.363184 12.014286 14.012121 14.240506 9.330097 11.769231
[193] 8.960000 14.917808 8.242991 11.852321 10.340426 8.284091
[199] 10.652459 9.000000 8.041026 7.488136 12.363636 6.016667
[205] 9.219048 8.584158 7.692308 14.815182 14.044248 7.650549
fish.alp<-fisher.alpha(bird_Ohio)
fish.alp
[1] 4.879601 7.265437 5.991450 7.139089 7.612305 6.987499
[7] 11.700302 8.514440 7.645338 8.203268 8.096417 9.316717
[13] 10.625244 11.170180 8.704701 10.438229 5.277516 5.354320
[19] 7.741632 8.704701 14.235471 5.563489 10.802080 8.827385
[25] 6.444680 6.644209 7.878918 7.161667 7.814550 6.610003
[31] 8.514440 11.689884 8.929434 8.136595 6.745910 9.869081
[37] 9.074933 12.010405 5.252615 6.879711 15.000086 13.840139
[43] 5.922455 6.745910 9.946552 7.656867 6.691741 5.685388
[49] 11.492806 6.987499 5.098572 15.718214 7.483241 10.136431
[55] 22.398229 8.549933 7.182494 6.227126 4.586486 9.261872
[61] 7.353659 12.333742 9.181666 5.292913 7.088144 9.348894
[67] 9.392030 10.625244 8.326654 6.264404 6.264404 6.444680
[73] 8.704701 8.347135 8.791663 8.660992 10.665986 7.912277
[79] 7.612305 6.828399 6.040326 9.650566 2.342557 8.717218
[85] 6.781181 10.483605 7.896600 6.456369 6.369414 6.207709
[91] 7.353659 8.306262 4.776899 4.076606 6.879711 9.238619
[97] 14.386674 9.915005 9.749784 12.719495 9.512046 12.467435
[103] 14.572309 4.771091 13.095785 6.286631 8.525511 7.904514
[109] 8.514440 8.136595 5.007071 8.347135 7.490234 6.559906
[115] 7.088144 6.132369 10.691663 15.780397 11.492806 6.973786
[121] 8.347135 8.660992 9.031307 8.266633 11.641119 13.465722
[127] 6.745910 8.536862 6.127733 9.185480 6.456369 5.316444
[133] 10.886950 6.712734 10.277584 14.105449 12.719495 7.565648
[139] 14.166726 8.614305 13.911898 8.416321 4.257215 10.505202
[145] 17.331388 7.139089 5.780910 6.610003 4.928004 9.228867
[151] 18.363340 12.375997 6.745910 11.212185 16.327612 8.203268
[157] 8.660992 7.374796 8.266633 10.885075 7.490234 17.764531
[163] 7.374796 15.828827 10.277584 10.366882 12.624488 11.851265
[169] 11.519965 7.088144 4.850244 8.071292 9.946552 6.644209
[175] 9.181666 8.198934 5.925432 6.444680 7.904514 5.521350
[181] 6.444680 18.528711 6.227126 8.266633 8.536862 13.353647
[187] 6.564138 8.096417 11.284101 11.323066 7.182494 10.976162
[193] 8.306262 21.505636 5.612435 14.105050 9.454690 6.132369
[199] 9.060475 8.198934 8.306262 7.612305 7.992375 3.725191
[205] 8.024966 7.161667 7.959047 12.375997 11.156386 9.710044
Div.Ind<-cbind.data.frame(shannon, simpson, invsimpson,fish.alp)
Div.Ind
summary(Div.Ind)
shannon simpson invsimpson
Min. :1.499 Min. :0.7321 Min. : 3.733
1st Qu.:2.334 1st Qu.:0.8788 1st Qu.: 8.251
Median :2.499 Median :0.8961 Median : 9.629
Mean :2.502 Mean :0.8936 Mean :10.239
3rd Qu.:2.669 3rd Qu.:0.9148 3rd Qu.:11.744
Max. :3.161 Max. :0.9519 Max. :20.804
fish.alp
Min. : 2.343
1st Qu.: 6.746
Median : 8.267
Mean : 8.912
3rd Qu.:10.420
Max. :22.398
data("env_Ohio")
Warning: data set ‘env_Ohio’ not found
env_Ohio
env.Ohio.Div<-cbind.data.frame(env_Ohio, Div.Ind)
env.Ohio.Div
summary(env.Ohio.Div$Habitat)
Length Class Mode
0 NULL NULL
library("readxl")
colnames(env_Ohio)
[1] "all_stem_den" "big_stem_bas" "can_covr_mea" "can_heig_mea"
[5] "HABITAT"
colnames(env_Ohio)[colnames(env_Ohio) == "ELT"] <- "Habitat"
colnames(env_Ohio)
[1] "all_stem_den" "big_stem_bas" "can_covr_mea" "can_heig_mea"
[5] "HABITAT"
data("env_Ohio")
Warning: data set ‘env_Ohio’ not found
env_Ohio
bird_Ohio.env.Div<-cbind.data.frame(env_Ohio, Div.Ind)
bird_Ohio.env.Div
colnames(bird_Ohio.env.Div)
[1] "all_stem_den" "big_stem_bas" "can_covr_mea" "can_heig_mea"
[5] "HABITAT" "shannon" "simpson" "invsimpson"
[9] "fish.alp"
bird_Ohio.env.Div$HABITAT<-as.factor(bird_Ohio.env.Div$HABITAT)
levels(bird_Ohio.env.Div$HABITAT)<-c("do","dm", "wm")
summary(bird_Ohio.env.Div$HABITAT)
do dm wm
59 96 55
library("rstatix")
env.Ohio.Div %>%
group_by(HABITAT) %>%
get_summary_stats(shannon, type = "mean_sd")
env.Ohio.Div %>%
group_by(HABITAT) %>%
get_summary_stats(simpson, type = "mean_sd")
env.Ohio.Div %>%
group_by(HABITAT) %>%
get_summary_stats(invsimpson, type = "mean_sd")
env.Ohio.Div %>%
group_by(HABITAT) %>%
get_summary_stats(fish.alp, type = "mean_sd")
library("ggplot2")
Shanon.habitat<-ggplot(env.Ohio.Div, aes(x = HABITAT, y = shannon, fill = HABITAT)) +
geom_boxplot() +
stat_summary(fun = mean, geom = "point", shape =21, size = 3, colour = "black", fill="yellow")
Simp.habitat<-ggplot(env.Ohio.Div, aes(x = HABITAT, y = simpson, fill = HABITAT)) +
geom_boxplot() +
stat_summary(fun = mean, geom = "point", shape =21, size = 3, colour = "black", fill="yellow")
InvSimp.habitat<-ggplot(env.Ohio.Div, aes(x = HABITAT, y = invsimpson, fill = HABITAT)) +
geom_boxplot() +
stat_summary(fun = mean, geom = "point", shape =21, size = 3, colour = "black", fill="yellow")
Fish.habitat<-ggplot(env.Ohio.Div, aes(x = HABITAT, y = fish.alp, fill = HABITAT)) +
geom_boxplot() +
stat_summary(fun = mean, geom = "point", shape =21, size = 3, colour = "black", fill="yellow")
library("gridExtra")
Warning: package ‘gridExtra’ was built under R version 4.4.2
grid.arrange(Shanon.habitat, Simp.habitat, InvSimp.habitat, Fish.habitat,
nrow=2, ncol=2)
shannon_aov <- aov(env.Ohio.Div$shannon ~ env.Ohio.Div$HABITAT)
summary(shannon_aov)
Df Sum Sq Mean Sq F value Pr(>F)
env.Ohio.Div$HABITAT 2 0.399 0.19958 2.817 0.0621 .
Residuals 207 14.668 0.07086
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
simpson_aov <- aov(env.Ohio.Div$simpson ~ env.Ohio.Div$HABITAT)
summary(simpson_aov)
Df Sum Sq Mean Sq F value Pr(>F)
env.Ohio.Div$HABITAT 2 0.00583 0.002916 2.776 0.0646 .
Residuals 207 0.21744 0.001050
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
invsimpson_aov <- aov(env.Ohio.Div$invsimpson ~ env.Ohio.Div$HABITAT)
summary(invsimpson_aov)
Df Sum Sq Mean Sq F value Pr(>F)
env.Ohio.Div$HABITAT 2 44.5 22.262 2.438 0.0899 .
Residuals 207 1890.5 9.133
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
fish.alp_aov <- aov(env.Ohio.Div$fish.alp ~ env.Ohio.Div$HABITAT)
summary(fish.alp_aov)
Df Sum Sq Mean Sq F value Pr(>F)
env.Ohio.Div$HABITAT 2 11.3 5.639 0.562 0.571
Residuals 207 2077.8 10.037
distance_matrix<-vegdist(env.Ohio.Div[,9:9], method="bray", binary=FALSE)
adonis2(distance_matrix ~ HABITAT, data=env.Ohio.Div)
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = distance_matrix ~ HABITAT, data = env.Ohio.Div)
Df SumOfSqs R2 F Pr(>F)
Model 2 0.0387 0.00746 0.7778 0.468
Residual 207 5.1467 0.99254
Total 209 5.1854 1.00000
shannon_Tukey<-TukeyHSD(shannon_aov, conf.level=.95, ordered = TRUE)
shannon_Tukey
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = env.Ohio.Div$shannon ~ env.Ohio.Div$HABITAT)
$`env.Ohio.Div$HABITAT`
diff lwr upr p adj
dm-do 0.04362627 -0.0603278576 0.1475804 0.5835556
wm-do 0.10671316 0.0004435631 0.2129827 0.0487920
wm-dm 0.06308689 -0.0546961030 0.1808699 0.4169311
shannon_Tukey_plot <- as.data.frame(shannon_Tukey$`env.Ohio.Div$HABITAT`)
shannon_Tukey_plot$comparison <- rownames(shannon_Tukey_plot)
shannon_Tukey_plot
library(ggplot2)
shannon_Tukey_plot_result<-ggplot(shannon_Tukey_plot, aes(x = comparison, y = diff)) +
geom_point() +
geom_errorbar(aes(ymin = lwr, ymax = upr), width = 0.2) +
labs(
title = "Tukey HSD Test Results for Shannon Diversity",
x = "Habitat Comparison",
y = "Pairwise Difference in Mean"
)
shannon_Tukey_plot_result
simpson_Tukey<-TukeyHSD(simpson_aov, conf.level=.95, ordered = TRUE)
simpson_Tukey
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = env.Ohio.Div$simpson ~ env.Ohio.Div$HABITAT)
$`env.Ohio.Div$HABITAT`
diff lwr upr p adj
dm-do 0.003429337 -9.227491e-03 0.01608616 0.7984209
wm-do 0.012841548 -9.719656e-05 0.02578029 0.0522377
wm-dm 0.009412211 -4.928335e-03 0.02375276 0.2701554
simpson_Tukey_plot <- as.data.frame(simpson_Tukey$`env.Ohio.Div$HABITAT`)
simpson_Tukey_plot$comparison <- rownames(simpson_Tukey_plot)
simpson_Tukey_plot
library(ggplot2)
simpson_Tukey_plot_result<-ggplot(simpson_Tukey_plot, aes(x = comparison, y = diff)) +
geom_point() +
geom_errorbar(aes(ymin = lwr, ymax = upr), width = 0.2) +
labs(
title = "Tukey HSD Test Results for Simpson Diversity",
x = "Habitat Comparison",
y = "Pairwise Difference in Mean"
)
simpson_Tukey_plot_result
invsimpson_Tukey<-TukeyHSD(invsimpson_aov, conf.level=.95, ordered = TRUE)
invsimpson_Tukey
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = env.Ohio.Div$invsimpson ~ env.Ohio.Div$HABITAT)
$`env.Ohio.Div$HABITAT`
diff lwr upr p adj
dm-do 0.3772352 -0.80294964 1.557420 0.7312016
wm-do 1.1278123 -0.07865997 2.334284 0.0723818
wm-dm 0.7505770 -0.58660612 2.087760 0.3828643
invsimpson_Tukey_plot <- as.data.frame(invsimpson_Tukey$`env.Ohio.Div$HABITAT`)
invsimpson_Tukey_plot$comparison <- rownames(invsimpson_Tukey_plot)
invsimpson_Tukey_plot
library(ggplot2)
invsimpson_Tukey_plot_result<-ggplot(invsimpson_Tukey_plot, aes(x = comparison, y = diff)) +
geom_point() +
geom_errorbar(aes(ymin = lwr, ymax = upr), width = 0.2) +
labs(
title = "Tukey HSD Test Results for Inverse Simpson's Diversity",
x = "Habitat Comparison",
y = "Pairwise Difference in Mean"
)
invsimpson_Tukey_plot_result
fish.alp_Tukey<-TukeyHSD(fish.alp_aov, conf.level=.95, ordered = TRUE)
fish.alp_Tukey
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = env.Ohio.Div$fish.alp ~ env.Ohio.Div$HABITAT)
$`env.Ohio.Div$HABITAT`
diff lwr upr p adj
dm-do 0.07742881 -1.1598183 1.314676 0.9880401
wm-do 0.55140864 -0.7133968 1.816214 0.5593155
wm-dm 0.47397984 -0.9278564 1.875816 0.7045578
fish.alp_Tukey_plot <- as.data.frame(fish.alp_Tukey$`env.Ohio.Div$HABITAT`)
fish.alp_Tukey_plot$comparison <- rownames(fish.alp_Tukey_plot)
fish.alp_Tukey_plot
library(ggplot2)
fish.alp_Tukey_plot_result<-ggplot(fish.alp_Tukey_plot, aes(x = comparison, y = diff)) +
geom_point() +
geom_errorbar(aes(ymin = lwr, ymax = upr), width = 0.2) +
labs(
title = "Tukey HSD Test Results for Fisher Alpha Diversity",
x = "Habitat Comparison",
y = "Pairwise Difference in Mean"
)
fish.alp_Tukey_plot_result
grid.arrange(shannon_Tukey_plot_result,Shanon.habitat,simpson_Tukey_plot_result,Simp.habitat,invsimpson_Tukey_plot_result,InvSimp.habitat,fish.alp_Tukey_plot_result,Fish.habitat,nrow=4, ncol=2)