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.
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 2.808416 2.632368 2.573988 2.450999 2.394499
[12] 2.670755 2.531704 2.538192 2.502138 2.671630 2.157016 2.003041 2.458384 2.517153 2.887236 2.238884
[23] 2.518361 2.459535 2.299249 2.324144 2.388357 2.443737 2.508801 2.239565 2.719239 2.669216 2.564513
[34] 2.220202 2.371608 2.728757 2.523222 2.698767 1.974502 2.403435 3.027143 2.929427 2.232029 2.326931
[45] 2.594871 2.428581 2.325057 1.853327 2.769102 2.504465 2.236733 2.948820 2.471493 2.608128 3.043401
[56] 2.600579 2.280595 2.117042 2.003623 2.829905 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 2.292052 2.391518 2.657784 2.475737 2.734494
[78] 2.356708 2.438921 2.292174 2.230160 2.444628 1.498985 2.542779 2.550645 2.736674 2.453161 2.339160
[89] 2.291078 2.258330 2.477123 2.602002 2.135238 2.001804 2.482235 2.668960 2.858335 2.649933 2.453522
[100] 2.865006 2.783952 2.998991 2.771560 2.295914 2.824489 2.383109 2.503965 2.634558 2.629183 2.519069
[111] 1.944464 2.445383 2.350606 2.406909 2.321891 2.375944 2.767400 2.843069 2.707323 2.148480 2.363373
[122] 2.489638 2.574951 2.517391 2.515402 2.707214 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 2.839435 2.716773 2.980252 2.197722 1.798709
[144] 2.885919 3.032903 2.485085 2.314192 2.241601 1.916081 2.567405 3.158537 2.891359 2.280094 2.767268
[155] 3.111523 2.444470 2.548230 2.518348 2.349092 2.625978 2.451639 2.764880 2.267142 3.161186 2.631644
[166] 2.692776 2.861356 2.906638 2.784373 2.308865 2.092852 2.622334 2.513477 2.282174 2.446827 2.388816
[177] 2.275937 2.354834 2.518677 2.193424 2.352495 2.779190 2.201542 2.549830 2.561493 2.912577 2.307692
[188] 2.637404 2.831398 2.850695 2.344426 2.665442 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 2.435551 2.375377 2.154783 2.893215 2.821822
[210] 2.495723
simpson<-diversity(bird_Ohio, index = "simpson")
simpson
[1] 0.7805326 0.8960000 0.9075255 0.8855556 0.9026709 0.9011446 0.9240237 0.9110302 0.9070295 0.8999270
[11] 0.8799049 0.9196694 0.8888889 0.8962500 0.9007561 0.9142661 0.8620038 0.8197531 0.8960302 0.9045369
[21] 0.9357639 0.8616864 0.8697979 0.8830796 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 0.8912000 0.9079717 0.8266667 0.8847737
[41] 0.9387269 0.9382716 0.8691650 0.8791308 0.9076543 0.8950000 0.8775000 0.7809917 0.9238683 0.8980229
[51] 0.8823143 0.9409722 0.8960459 0.9151874 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 0.8836806 0.8945578 0.9047852 0.8755556
[71] 0.8977778 0.8900227 0.8383743 0.8843537 0.9178994 0.8921324 0.9271163 0.8833792 0.8899955 0.8757396
[81] 0.8698061 0.8863772 0.7321429 0.9112500 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 0.9304734 0.9073433 0.8827977 0.9330652
[101] 0.9225839 0.9427660 0.9207786 0.8814879 0.9275148 0.8897929 0.8994646 0.9161111 0.9120708 0.9000000
[111] 0.7976000 0.8922902 0.8741319 0.8870392 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 0.8655500 0.8978052 0.8395062 0.9145408
[131] 0.8800000 0.8966837 0.9054134 0.8526786 0.9104132 0.9400889 0.9307670 0.8930664 0.9362500 0.9239452
[141] 0.9383673 0.8441358 0.7929240 0.9388889 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 0.8949804 0.9037901 0.8696377 0.9083176
[161] 0.8940972 0.9189189 0.8529779 0.9519312 0.9084298 0.9137329 0.9341564 0.9375000 0.9126658 0.8780992
[171] 0.8480726 0.9066607 0.8948148 0.8680556 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 0.8804283 0.9167658 0.9286332 0.9297778
[191] 0.8928200 0.9150327 0.8883929 0.9329660 0.8786848 0.9156283 0.9032922 0.8792867 0.9061250 0.8888889
[201] 0.8756378 0.8664554 0.9191176 0.8337950 0.8915289 0.8835063 0.8700000 0.9325017 0.9287965 0.8692904
inv.simpson<-diversity(bird_Ohio, index = "invsimpson")
inv.simpson
[1] 4.556485 9.615385 10.813793 8.737864 10.274419 10.115789 13.161994 11.239766 10.756098 9.992701
[11] 8.326733 12.448560 9.000000 9.638554 10.076190 11.664000 7.246575 5.547945 9.618182 10.475248
[21] 15.567568 7.229947 7.680365 8.552826 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 9.191176 10.866221 5.769231 8.678571
[41] 16.320388 16.200000 7.643216 8.273408 10.828877 9.523810 8.163265 4.566038 13.135135 9.806122
[51] 8.497207 16.941176 9.619632 11.790698 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 8.597015 9.483871 10.502564 8.035714
[71] 9.782609 9.092784 6.187135 8.647059 12.180180 9.270627 13.720497 8.574803 9.090535 8.047619
[81] 7.680851 8.801047 3.733333 11.267606 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 14.382979 10.792531 8.532258 14.939914
[101] 12.917211 17.472131 12.622857 8.437956 13.795918 9.073826 9.946746 11.920530 11.372781 10.000000
[111] 4.940711 9.284211 7.944828 8.852632 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 7.437710 9.785235 6.230769 11.701493
[131] 8.333333 9.679012 10.572327 6.787879 11.162362 16.691395 14.443983 9.351598 15.686275 13.148410
[141] 16.225166 6.415842 4.829146 16.363636 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 9.522034 10.393939 7.670927 10.907216
[161] 9.442623 12.333333 6.801700 20.803509 10.920578 11.591900 15.187500 16.000000 11.450262 8.203390
[171] 6.582090 10.713604 9.507042 7.578947 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 8.363184 12.014286 14.012121 14.240506
[191] 9.330097 11.769231 8.960000 14.917808 8.242991 11.852321 10.340426 8.284091 10.652459 9.000000
[201] 8.041026 7.488136 12.363636 6.016667 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 11.700302 8.514440 7.645338 8.203268
[11] 8.096417 9.316717 10.625244 11.170180 8.704701 10.438229 5.277516 5.354320 7.741632 8.704701
[21] 14.235471 5.563489 10.802080 8.827385 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 9.074933 12.010405 5.252615 6.879711
[41] 15.000086 13.840139 5.922455 6.745910 9.946552 7.656867 6.691741 5.685388 11.492806 6.987499
[51] 5.098572 15.718214 7.483241 10.136431 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 9.392030 10.625244 8.326654 6.264404
[71] 6.264404 6.444680 8.704701 8.347135 8.791663 8.660992 10.665986 7.912277 7.612305 6.828399
[81] 6.040326 9.650566 2.342557 8.717218 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 14.386674 9.915005 9.749784 12.719495
[101] 9.512046 12.467435 14.572309 4.771091 13.095785 6.286631 8.525511 7.904514 8.514440 8.136595
[111] 5.007071 8.347135 7.490234 6.559906 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 6.745910 8.536862 6.127733 9.185480
[131] 6.456369 5.316444 10.886950 6.712734 10.277584 14.105449 12.719495 7.565648 14.166726 8.614305
[141] 13.911898 8.416321 4.257215 10.505202 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 8.660992 7.374796 8.266633 10.885075
[161] 7.490234 17.764531 7.374796 15.828827 10.277584 10.366882 12.624488 11.851265 11.519965 7.088144
[171] 4.850244 8.071292 9.946552 6.644209 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 6.564138 8.096417 11.284101 11.323066
[191] 7.182494 10.976162 8.306262 21.505636 5.612435 14.105050 9.454690 6.132369 9.060475 8.198934
[201] 8.306262 7.612305 7.992375 3.725191 8.024966 7.161667 7.959047 12.375997 11.156386 9.710044
Div.Ind<-cbind.data.frame(shannon, simpson, inv.simpson,fish.alp)
Div.Ind
summary(Div.Ind)
shannon simpson inv.simpson fish.alp
Min. :1.499 Min. :0.7321 Min. : 3.733 Min. : 2.343
1st Qu.:2.334 1st Qu.:0.8788 1st Qu.: 8.251 1st Qu.: 6.746
Median :2.499 Median :0.8961 Median : 9.629 Median : 8.267
Mean :2.502 Mean :0.8936 Mean :10.239 Mean : 8.912
3rd Qu.:2.669 3rd Qu.:0.9148 3rd Qu.:11.744 3rd Qu.:10.420
Max. :3.161 Max. :0.9519 Max. :20.804 Max. :22.398
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
bird_Ohio.env.Div$Habitat <- as.factor(bird_Ohio.env.Div$Habitat)
colnames(bird_Ohio.env.Div)[which(colnames(bird_Ohio.env.Div)=="ELT")]<-"Habitat"
bird_Ohio.env.Div
summary(bird_Ohio.env.Div$Habitat)
dm do wm
59 96 55
library(rstatix)
bird_Ohio.env.Div %>%
group_by(Habitat) %>%
get_summary_stats(simpson, type = "mean_sd")
NA
bird_Ohio.env.Div %>%
group_by(Habitat) %>%
get_summary_stats(shannon, type = "mean_sd")
bird_Ohio.env.Div %>%
group_by(Habitat) %>%
get_summary_stats(inv.simpson, type = "mean_sd")
bird_Ohio.env.Div %>%
group_by(Habitat) %>%
get_summary_stats(fish.alp, type = "mean_sd")
Shanon.habitat<-ggplot(bird_Ohio.env.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(bird_Ohio.env.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(bird_Ohio.env.Div, aes(x = Habitat, y = inv.simpson, fill = Habitat)) +
geom_boxplot() +
stat_summary(fun = mean, geom = "point", shape =21, size = 3, colour = "black", fill="yellow")
Fish.habitat<-ggplot(bird_Ohio.env.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")
grid.arrange(Shanon.habitat, Simp.habitat, InvSimp.habitat, Fish.habitat,
nrow=2, ncol=2)
shannon_aov <- aov(bird_Ohio.env.Div$shannon ~ bird_Ohio.env.Div$Habitat)
summary(shannon_aov)
Df Sum Sq Mean Sq F value Pr(>F)
bird_Ohio.env.Div$Habitat 2 0.399 0.19958 2.817 0.0621
Residuals 207 14.668 0.07086
bird_Ohio.env.Div$Habitat .
Residuals
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
simpson_aov <- aov(bird_Ohio.env.Div$simpson ~ bird_Ohio.env.Div$Habitat)
summary(simpson_aov)
Df Sum Sq Mean Sq F value Pr(>F)
bird_Ohio.env.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
inv.simpson_aov <- aov(bird_Ohio.env.Div$inv.simpson ~ bird_Ohio.env.Div$Habitat)
summary(inv.simpson_aov)
Df Sum Sq Mean Sq F value Pr(>F)
bird_Ohio.env.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(bird_Ohio.env.Div$fish.alp ~ bird_Ohio.env.Div$Habitat)
summary(fish.alp_aov)
Df Sum Sq Mean Sq F value Pr(>F)
bird_Ohio.env.Div$Habitat 2 11.3 5.639 0.562 0.571
Residuals 207 2077.8 10.037
distance_matrix<-vegdist(bird_Ohio.env.Div[ ,6:9], method="bray", binary=FALSE)
adonis2(distance_matrix ~ Habitat, data=bird_Ohio.env.Div)
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 = bird_Ohio.env.Div$shannon ~ bird_Ohio.env.Div$Habitat)
$`bird_Ohio.env.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
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 = bird_Ohio.env.Div$simpson ~ bird_Ohio.env.Div$Habitat)
$`bird_Ohio.env.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
inv.simpson_Tukey<-TukeyHSD(inv.simpson_aov, conf.level=.95, ordered = TRUE)
inv.simpson_Tukey
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = bird_Ohio.env.Div$inv.simpson ~ bird_Ohio.env.Div$Habitat)
$`bird_Ohio.env.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
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 = bird_Ohio.env.Div$fish.alp ~ bird_Ohio.env.Div$Habitat)
$`bird_Ohio.env.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
shannon_Tukey_plot <- as.data.frame(shannon_Tukey$`bird_Ohio.env.Div$Habitat`)
shannon_Tukey_plot$comparison <- rownames(shannon_Tukey_plot)
shannon_Tukey_plot
simpson_Tukey_plot <- as.data.frame(simpson_Tukey$`bird_Ohio.env.Div$Habitat`)
simpson_Tukey_plot$comparison <- rownames(simpson_Tukey_plot)
simpson_Tukey_plot
inv.simpson_Tukey_plot <- as.data.frame(inv.simpson_Tukey$`bird_Ohio.env.Div$Habitat`)
inv.simpson_Tukey_plot$comparison <- rownames(inv.simpson_Tukey_plot)
inv.simpson_Tukey_plot
fish.alp_Tukey_plot <- as.data.frame(fish.alp_Tukey$`bird_Ohio.env.Div$Habitat`)
fish.alp_Tukey_plot$comparison <- rownames(fish.alp_Tukey_plot)
fish.alp_Tukey_plot
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
shannon_Tukey_plot_result_meandiff<-shannon_Tukey_plot_result +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
geom_hline(yintercept=0, linetype="dashed", color = "red")
shannon_Tukey_plot_result_meandiff
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
simpson_Tukey_plot_result_meandiff<-simpson_Tukey_plot_result +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
geom_hline(yintercept=0, linetype="dashed", color = "red")
simpson_Tukey_plot_result_meandiff
inv.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 Inv.simpson Diversity",
x = "Habitat Comparison",
y = "Pairwise Difference in Mean"
)
inv.simpson_Tukey_plot_result
inv.simpson_Tukey_plot_result_meandiff<-inv.simpson_Tukey_plot_result +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
geom_hline(yintercept=0, linetype="dashed", color = "red")
inv.simpson_Tukey_plot_result_meandiff
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 Fish.Alp Diversity",
x = "Habitat Comparison",
y = "Pairwise Difference in Mean"
)
fish.alp_Tukey_plot_result
fish.alp_Tukey_plot_result_meandiff<-fish.alp_Tukey_plot_result +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
geom_hline(yintercept=0, linetype="dashed", color = "red")
fish.alp_Tukey_plot_result_meandiff
Shanon.habitat
Simp.habitat
InvSimp.habitat
Fish.habitat
grid.arrange(Shanon.habitat, Simp.habitat, InvSimp.habitat, Fish.habitat, nrow=2, ncol=2)