library(ordinal)
## Warning: package 'ordinal' was built under R version 4.1.3
library(MASS)
## Warning: package 'MASS' was built under R version 4.1.3
library(brant)
## Warning: package 'brant' was built under R version 4.1.3
library(AER)
## Warning: package 'AER' was built under R version 4.1.3
## Loading required package: car
## Warning: package 'car' was built under R version 4.1.3
## Loading required package: carData
## Loading required package: lmtest
## Warning: package 'lmtest' was built under R version 4.1.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.1.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: sandwich
## Warning: package 'sandwich' was built under R version 4.1.3
## Loading required package: survival
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.1.3
library(aod)
## Warning: package 'aod' was built under R version 4.1.3
##
## Attaching package: 'aod'
## The following object is masked from 'package:survival':
##
## rats
library(gt)
## Warning: package 'gt' was built under R version 4.1.3
library(jmv)
## Warning: package 'jmv' was built under R version 4.1.3
library(rcompanion)
## Warning: package 'rcompanion' was built under R version 4.1.3
library(apaTables)
## Warning: package 'apaTables' was built under R version 4.1.3
library(apaText)
## Warning: package 'apaText' was built under R version 4.1.3
library(readr)
## Warning: package 'readr' was built under R version 4.1.3
Read in Mosquito data
Msqt <- read_csv("BCH_MSQT_7_27_22.csv", col_types = cols(BCH_ID = col_factor(levels = c("1",
"2", "21", "33", "51", "53", "59", "66",
"68", "77", "88", "91", "188", "246",
"267", "270", "313", "329", "360", "371",
"429", "456", "493", "565", "571", "587",
"596", "651", "671", "872", "909", "932",
"937", "949", "955", "968", "971", "972",
"985", "1017", "1092", "1190", "1204")),
Jul_Date = col_number(), Dt_2020 = col_number(),
Dt_2021 = col_number(), CmbCrt = col_factor(levels = c("none",
"silv", "gopl")), none = col_number(),
silv = col_number(), pc1 = col_factor(levels = c("exurban",
"suburban", "urban")), Exurban = col_number(),
Suburban = col_number(), Ae_albopictus = col_number(),
Cx_childesteri = col_number(), Cx_erraticus = col_number(),
Cx_pipiens = col_number(), Cx_po = col_number(),
Oc._c_canadensis = col_number(), `Oc_c_ mathesoni` = col_number(),
Oc_increpitus = col_number(), Oc_zoosophus = col_number(),
Tx_r_rutilus = col_number(), Ae_japanicus = col_number(),
Oc_sollicitans = col_number(), Cx_restuans = col_number(),
Abun = col_number()))
View(Msqt)
Read in Mosquito data with “none” level certified home removed
Msqt_NoNo <- read_csv("Msqt_NoNo.csv", col_types = cols(BCH_ID = col_factor(levels = c("1",
"2", "21", "33", "51", "53", "59", "66",
"68", "77", "88", "91", "188", "246",
"267", "270", "313", "329", "360", "371",
"429", "456", "493", "565", "571", "587",
"596", "651", "671", "872", "909", "932",
"937", "949", "955", "968", "971", "972",
"985", "1017", "1092", "1190", "1204")),
Jul_Date = col_number(), Dt_2020 = col_number(),
Dt_2021 = col_number(), CmbCrt = col_factor(levels = c("none",
"silv", "gopl")), none = col_number(),
silv = col_number(), pc1 = col_factor(levels = c("exurban",
"suburban", "urban")), Exurban = col_number(),
Suburban = col_number(), Ae_albopictus = col_number(),
Cx_childesteri = col_number(), Cx_erraticus = col_number(),
Cx_pipiens = col_number(), Cx_po = col_number(),
Oc._c_canadensis = col_number(), `Oc_c_ mathesoni` = col_number(),
Oc_increpitus = col_number(), Oc_zoosophus = col_number(),
Tx_r_rutilus = col_number(), Ae_japanicus = col_number(),
Oc_sollicitans = col_number(), Cx_restuans = col_number(),
Abun = col_number()))
View(Msqt_NoNo)
Ordinal Logistic Regression
## BCH Cert Level OLM
## SR
polrSR <- polr(formula = CmbCrt~EstSR+Jul_Date+Dt_2020+pc1+Abun,data = Msqt, Hess = TRUE)
brant(polrSR)
## --------------------------------------------
## Test for X2 df probability
## --------------------------------------------
## Omnibus 3.29 6 0.77
## EstSR 0.06 1 0.8
## Jul_Date 0.01 1 0.91
## Dt_2020 0 1 0.95
## pc1suburban 0.35 1 0.56
## pc1urban 0.01 1 0.91
## Abun 2.71 1 0.1
## --------------------------------------------
##
## H0: Parallel Regression Assumption holds
summary(polrSR)
## Warning in sqrt(diag(vc)): NaNs produced
## Call:
## polr(formula = CmbCrt ~ EstSR + Jul_Date + Dt_2020 + pc1 + Abun,
## data = Msqt, Hess = TRUE)
##
## Coefficients:
## Value Std. Error t value
## EstSR 0.241689 0.039425 6.1303
## Jul_Date 0.003392 NaN NaN
## Dt_2020 3.336195 0.011371 293.3841
## pc1suburban 0.001364 0.009169 0.1488
## pc1urban 0.008458 0.006999 1.2084
## Abun 0.005061 0.004185 1.2092
##
## Intercepts:
## Value Std. Error t value
## none|silv 71.7957 0.0227 3159.5168
## silv|gopl 73.2305 0.1528 479.3456
##
## Residual Deviance: 353.7708
## AIC: 369.7708
coeftest(polrSR)
## Warning in sqrt(diag(vc)): NaNs produced
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## EstSR 0.2416895 0.0394253 6.1303 8.77e-10 ***
## Jul_Date 0.0033923 NaN NaN NaN
## Dt_2020 3.3361951 0.0113714 293.3841 < 2.2e-16 ***
## pc1suburban 0.0013642 0.0091686 0.1488 0.8817
## pc1urban 0.0084582 0.0069995 1.2084 0.2269
## Abun 0.0050606 0.0041852 1.2092 0.2266
## none|silv 71.7956835 0.0227236 3159.5168 < 2.2e-16 ***
## silv|gopl 73.2304743 0.1527718 479.3456 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coeftest(polrSR))
## Warning in sqrt(diag(vc)): NaNs produced
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## EstSR 1.2734e+00 1.0402e+00 4.5958e+02 1.000
## Jul_Date 1.0034e+00 NaN NaN NaN
## Dt_2020 2.8112e+01 1.0114e+00 2.6008e+127 1.000
## pc1suburban 1.0014e+00 1.0092e+00 1.1604e+00 2.415
## pc1urban 1.0085e+00 1.0070e+00 3.3481e+00 1.255
## Abun 1.0051e+00 1.0042e+00 3.3507e+00 1.254
## none|silv 1.5152e+31 1.0230e+00 Inf 1.000
## silv|gopl 6.3620e+31 1.1651e+00 1.5036e+208 1.000
## Shan H
polrSh <- polr(formula = CmbCrt~EstShan+Jul_Date+Dt_2020+pc1+Abun,data = Msqt, Hess = TRUE)
brant(polrSh)
## --------------------------------------------
## Test for X2 df probability
## --------------------------------------------
## Omnibus 3.3 6 0.77
## EstShan 0.01 1 0.93
## Jul_Date 0.01 1 0.92
## Dt_2020 0 1 0.97
## pc1suburban 0.38 1 0.54
## pc1urban 0.02 1 0.89
## Abun 2.59 1 0.11
## --------------------------------------------
##
## H0: Parallel Regression Assumption holds
summary(polrSh)
## Warning in sqrt(diag(vc)): NaNs produced
## Call:
## polr(formula = CmbCrt ~ EstShan + Jul_Date + Dt_2020 + pc1 +
## Abun, data = Msqt, Hess = TRUE)
##
## Coefficients:
## Value Std. Error t value
## EstShan 0.487319 0.039406 12.367
## Jul_Date 0.002745 NaN NaN
## Dt_2020 2.595959 0.014742 176.092
## pc1suburban -0.082131 0.012736 -6.448
## pc1urban 0.015350 0.010657 1.440
## Abun 0.005481 0.004085 1.342
##
## Intercepts:
## Value Std. Error t value
## none|silv 58.1943 0.0319 1824.8491
## silv|gopl 59.6515 0.1486 401.5051
##
## Residual Deviance: 350.4478
## AIC: 366.4478
coeftest(polrSh)
## Warning in sqrt(diag(vc)): NaNs produced
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## EstShan 0.4873187 0.0394056 12.3668 < 2.2e-16 ***
## Jul_Date 0.0027449 NaN NaN NaN
## Dt_2020 2.5959589 0.0147421 176.0921 < 2.2e-16 ***
## pc1suburban -0.0821311 0.0127365 -6.4485 1.13e-10 ***
## pc1urban 0.0153500 0.0106572 1.4403 0.1498
## Abun 0.0054807 0.0040854 1.3415 0.1797
## none|silv 58.1943199 0.0318899 1824.8491 < 2.2e-16 ***
## silv|gopl 59.6514943 0.1485697 401.5051 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coeftest(polrSh))
## Warning in sqrt(diag(vc)): NaNs produced
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## EstShan 1.6280e+00 1.0402e+00 2.3486e+05 1.000
## Jul_Date 1.0028e+00 NaN NaN NaN
## Dt_2020 1.3409e+01 1.0149e+00 2.9911e+76 1.000
## pc1suburban 9.2115e-01 1.0128e+00 1.6000e-03 1.000
## pc1urban 1.0155e+00 1.0107e+00 4.2222e+00 1.162
## Abun 1.0055e+00 1.0041e+00 3.8249e+00 1.197
## none|silv 1.8770e+25 1.0324e+00 Inf 1.000
## silv|gopl 8.0596e+25 1.1602e+00 2.3520e+174 1.000
## Simpson
polrSi <- polr(formula = CmbCrt~EstSimp+Jul_Date+Dt_2020+pc1+Abun,data = Msqt, Hess = TRUE)
brant(polrSi)
## --------------------------------------------
## Test for X2 df probability
## --------------------------------------------
## Omnibus 3.5 6 0.74
## EstSimp 0.31 1 0.57
## Jul_Date 0.03 1 0.87
## Dt_2020 0.01 1 0.91
## pc1suburban 0.45 1 0.5
## pc1urban 0.02 1 0.9
## Abun 2.67 1 0.1
## --------------------------------------------
##
## H0: Parallel Regression Assumption holds
summary(polrSi)
## Warning in sqrt(diag(vc)): NaNs produced
## Call:
## polr(formula = CmbCrt ~ EstSimp + Jul_Date + Dt_2020 + pc1 +
## Abun, data = Msqt, Hess = TRUE)
##
## Coefficients:
## Value Std. Error t value
## EstSimp 0.694222 0.037332 18.596
## Jul_Date 0.002950 NaN NaN
## Dt_2020 2.733747 0.016492 165.758
## pc1suburban -0.077035 0.013729 -5.611
## pc1urban 0.014285 0.013041 1.095
## Abun 0.005106 0.004138 1.234
##
## Intercepts:
## Value Std. Error t value
## none|silv 62.6710 0.0365 1714.9343
## silv|gopl 64.1364 0.1455 440.8219
##
## Residual Deviance: 349.1876
## AIC: 365.1876
coeftest(polrSi)
## Warning in sqrt(diag(vc)): NaNs produced
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## EstSimp 0.6942224 0.0373315 18.5961 < 2.2e-16 ***
## Jul_Date 0.0029499 NaN NaN NaN
## Dt_2020 2.7337468 0.0164924 165.7579 < 2.2e-16 ***
## pc1suburban -0.0770352 0.0137285 -5.6113 2.008e-08 ***
## pc1urban 0.0142848 0.0130415 1.0953 0.2734
## Abun 0.0051058 0.0041383 1.2338 0.2173
## none|silv 62.6709896 0.0365443 1714.9343 < 2.2e-16 ***
## silv|gopl 64.1364361 0.1454929 440.8219 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
exp(coeftest(polrSi))
## Warning in sqrt(diag(vc)): NaNs produced
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## EstSimp 2.0021e+00 1.0380e+00 1.1918e+08 1.000
## Jul_Date 1.0030e+00 NaN NaN NaN
## Dt_2020 1.5390e+01 1.0166e+00 9.7221e+71 1.000
## pc1suburban 9.2586e-01 1.0138e+00 3.7000e-03 1.000
## pc1urban 1.0144e+00 1.0131e+00 2.9902e+00 1.314
## Abun 1.0051e+00 1.0042e+00 3.4343e+00 1.243
## none|silv 1.6507e+27 1.0372e+00 Inf 1.000
## silv|gopl 7.1466e+27 1.1566e+00 2.7958e+191 1.000
Abunudance glm
## SR
glmSR.ab <- glm(formula = Abun~EstSR+Jul_Date+Dt_2020+none+silv+Exurban+Suburban,family = gaussian, data = Msqt)
summary(glmSR.ab)
##
## Call:
## glm(formula = Abun ~ EstSR + Jul_Date + Dt_2020 + none + silv +
## Exurban + Suburban, family = gaussian, data = Msqt)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -53.198 -18.112 -5.018 8.304 150.583
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2697.3033 2171.6121 1.242 0.21609
## EstSR 10.0579 3.6910 2.725 0.00717 **
## Jul_Date -0.1270 0.1024 -1.240 0.21675
## Dt_2020 -99.8743 105.5770 -0.946 0.34563
## none -6.6855 6.0541 -1.104 0.27118
## silv 4.7702 6.0494 0.789 0.43159
## Exurban -12.0391 6.0696 -1.984 0.04908 *
## Suburban -8.1002 5.9080 -1.371 0.17234
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 971.2978)
##
## Null deviance: 221705 on 162 degrees of freedom
## Residual deviance: 150551 on 155 degrees of freedom
## AIC: 1593.6
##
## Number of Fisher Scoring iterations: 2
exp(coeftest(glmSR.ab))
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) Inf Inf 3.4628 1.239
## EstSR 2.3339e+04 4.0086e+01 15.2557 1.006
## Jul_Date 8.8076e-01 1.1078e+00 0.2893 1.240
## Dt_2020 4.2182e-44 7.1041e+45 0.3883 1.411
## none 1.2489e-03 4.2587e+02 0.3314 1.309
## silv 1.1794e+02 4.2387e+02 2.2002 1.538
## Exurban 5.9084e-06 4.3252e+02 0.1376 1.048
## Suburban 3.0347e-04 3.6795e+02 0.2538 1.186
exp(confint(glmSR.ab))
## Waiting for profiling to be done...
## 2.5 % 97.5 %
## (Intercept) 0.000000e+00 Inf
## EstSR 1.683743e+01 3.235228e+07
## Jul_Date 7.206341e-01 1.076462e+00
## Dt_2020 5.725687e-134 3.107649e+46
## none 8.774907e-09 1.777598e+02
## silv 8.363247e-04 1.663191e+07
## Exurban 4.027087e-11 8.668490e-01
## Suburban 2.839605e-09 3.243253e+01
## Shannon H
glmSh.ab <- glm(formula = Abun~EstShan+Jul_Date+Dt_2020+none+silv+Exurban+Suburban,family = gaussian, data = Msqt)
summary(glmSh.ab)
##
## Call:
## glm(formula = Abun ~ EstShan + Jul_Date + Dt_2020 + none + silv +
## Exurban + Suburban, family = gaussian, data = Msqt)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -50.938 -17.140 -5.767 7.819 166.313
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1696.15308 2184.92654 0.776 0.4388
## EstShan 4.15146 4.05232 1.024 0.3072
## Jul_Date -0.07944 0.10299 -0.771 0.4417
## Dt_2020 -45.90042 105.90497 -0.433 0.6653
## none -7.21260 6.23748 -1.156 0.2493
## silv 4.53013 6.19221 0.732 0.4655
## Exurban -11.08365 6.18085 -1.793 0.0749 .
## Suburban -6.38407 6.07157 -1.051 0.2947
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 1010.983)
##
## Null deviance: 221705 on 162 degrees of freedom
## Residual deviance: 156702 on 155 degrees of freedom
## AIC: 1600.1
##
## Number of Fisher Scoring iterations: 2
exp(coeftest(glmSh.ab))
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) Inf Inf 2.1734 1.549
## EstShan 6.3527e+01 5.7531e+01 2.7856 1.357
## Jul_Date 9.2364e-01 1.1085e+00 0.4624 1.553
## Dt_2020 1.1633e-20 9.8616e+45 0.6483 1.944
## none 7.3723e-04 5.1157e+02 0.3146 1.281
## silv 9.2771e+01 4.8893e+02 2.0784 1.591
## Exurban 1.5361e-05 4.8340e+02 0.1664 1.076
## Suburban 1.6882e-03 4.3336e+02 0.3494 1.341
exp(confint(glmSh.ab))
## Waiting for profiling to be done...
## 2.5 % 97.5 %
## (Intercept) 0.000000e+00 Inf
## EstShan 2.257421e-02 1.787731e+05
## Jul_Date 7.548123e-01 1.130218e+00
## Dt_2020 8.302795e-111 1.629966e+70
## none 3.616232e-09 1.502985e+02
## silv 4.972693e-04 1.730732e+07
## Exurban 8.419528e-11 2.802710e+00
## Suburban 1.146319e-08 2.486349e+02
glmSi.ab <- glm(formula = Abun~EstSimp+Jul_Date+Dt_2020+none+silv+Exurban+Suburban,family = gaussian, data = Msqt)
summary(glmSi.ab)
##
## Call:
## glm(formula = Abun ~ EstSimp + Jul_Date + Dt_2020 + none + silv +
## Exurban + Suburban, family = gaussian, data = Msqt)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -51.561 -17.044 -5.021 9.371 165.169
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1776.62194 2172.94196 0.818 0.4148
## EstSimp 6.90235 4.93682 1.398 0.1641
## Jul_Date -0.08334 0.10242 -0.814 0.4171
## Dt_2020 -51.13534 105.34752 -0.485 0.6281
## none -6.64003 6.24279 -1.064 0.2891
## silv 5.02037 6.19589 0.810 0.4190
## Exurban -10.99681 6.15905 -1.785 0.0761 .
## Suburban -6.63509 6.01450 -1.103 0.2717
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for gaussian family taken to be 1005.152)
##
## Null deviance: 221705 on 162 degrees of freedom
## Residual deviance: 155799 on 155 degrees of freedom
## AIC: 1599.2
##
## Number of Fisher Scoring iterations: 2
exp(coeftest(glmSi.ab))
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) Inf Inf 2.2651 1.512
## EstSimp 9.9461e+02 1.3933e+02 4.0476 1.176
## Jul_Date 9.2004e-01 1.1079e+00 0.4432 1.516
## Dt_2020 6.1973e-23 5.6474e+45 0.6155 1.873
## none 1.3070e-03 5.1429e+02 0.3452 1.333
## silv 1.5147e+02 4.9073e+02 2.2485 1.519
## Exurban 1.6755e-05 4.7298e+02 0.1677 1.077
## Suburban 1.3135e-03 4.0932e+02 0.3318 1.310
exp(confint(glmSi.ab))
## Waiting for profiling to be done...
## 2.5 % 97.5 %
## (Intercept) 0.000000e+00 Inf
## EstSimp 6.243388e-02 1.584477e+07
## Jul_Date 7.527059e-01 1.124578e+00
## Dt_2020 1.318969e-112 2.911900e+67
## none 6.344551e-09 2.692397e+02
## silv 8.060541e-04 2.846256e+07
## Exurban 9.584103e-11 2.929144e+00
## Suburban 9.973844e-09 1.729707e+02
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
Density graph of iNext estimates of Species Richness for the ’20 & ’21 season, grouped by BCH certification Level
Msqt.DenPlt <- ggplot(Msqt,aes(EstSR))
Msqt.DenPlt+geom_density(aes(fill=factor(CmbCrt)), alpha=0.8) +
labs(title="Density plot",
subtitle="iNext estimates of Species Richness grouped by BCH certification Level",
caption="Source: iNEXT",
x="Species Richness",
fill="certification Level")
Msqt_NN.DenPlt <- ggplot(Msqt_NoNo,aes(EstSR))
Msqt_NN.DenPlt+geom_density(aes(fill=factor(CmbCrt)), alpha=0.8)+
labs(title="Density plot",
subtitle="iNext estimates of Species Richness grouped by BCH certification Level with none certificated removed ",
caption="Source: iNEXT",
x="Species Richness",
fill="certification Level")
Density graph of iNext estimates of Species Abundance for the ’20 & ’21 season, grouped by Species Abundance
Msqt.DenPlt <- ggplot(Msqt,aes(Abun))
Msqt.DenPlt+geom_density(aes(fill=factor(CmbCrt)), alpha=0.8) +
labs(title="Density plot",
subtitle="iNext estimates of Species Abundance by BCH certification Level",
caption="Source: iNEXT",
x="Species Abundance",
fill="certification Level")
Msqt_NN.DenPlt <- ggplot(Msqt_NoNo,aes(Abun))
Msqt_NN.DenPlt+geom_density(aes(fill=factor(CmbCrt)), alpha=0.8)+
labs(title="Density plot",
subtitle="iNext estimates of Species Abundance by BCH certification Level, with none certificated removed ",
caption="Source: iNEXT",
x="Species Abundance",
fill="certification Level")