####FINAL MPXV ANALYSES setwd("~/documents/UCLA Grad Docs/Monkeypox Project/Final Analysis/") #####(1) COMPARING MPXV INFECTION ACROSS SPECIES, COLLECTION YEAR AND MUSEUM #### ######### (1a) Finding species prevalence + 95% CI ## MPXV_sp <- read.csv(file='MPXVPosProp_spp_CI.csv',sep=',', header=T) #read in csv file MPXV_sp blank <- matrix(NA,12,9) #create empty matrix to add to csv colnames(blank) <- c("prev_G2RG", "G2RG_lowCI", "G2RG_highCI", "prev_G2RWA", "G2RWA_lowCI", "G2RWA_highCI","prev_both", "both_lowCI", "both_highCI") MPXV_sp <- cbind(MPXV_sp,blank) citation("Hmisc") tapply(mydata.ALL$POS_Both, mydata.ALL$species.code, length) #loop for calculating prevalence levels + 95% CI for (ii in 1:length(MPXV_sp$Species)){ MPXV_sp[ii, 6:8] <- binconf(MPXV_sp[ii,2], MPXV_sp[ii,5], alpha=0.05, method="exact") #fill in for G2R_G MPXV_sp[ii, 9:11] <- binconf(MPXV_sp[ii,3], MPXV_sp[ii,5], alpha=0.05, method="exact") #fill in for G2R_G MPXV_sp[ii, 12:14] <- binconf(MPXV_sp[ii,4], MPXV_sp[ii,5], alpha=0.05, method="exact") #fill in for G2R_G } write.csv(MPXV_sp, file = 'MPXVPosProp_spp_CI.csv') ###########(1b) Binomial logistical regression models mydata.ALL.ADM3 <- read.csv("allsamples_binnedyear_ADM3.csv", sep = ",", header = TRUE) ##csv without localities > 25 km #subset data so include only those with species with many samples mydata.ALL.ADM3.subset <- subset(mydata.ALL.ADM3.subset, subset=species.co!="F_ba") mydata.ALL.ADM3.subset <- subset(mydata.ALL.ADM3.subset, subset=species.co!="F_is") mydata.ALL.ADM3.subset <- subset(mydata.ALL.ADM3.subset, subset=species.co!="F_leo") mydata.ALL.ADM3.subset <- subset(mydata.ALL.ADM3.subset, subset=species.co!="F_leu") mydata.ALL.ADM3.subset <- subset(mydata.ALL.ADM3, subset=species.co!="F_su") mydata.ALL.ADM3.subset <- subset(mydata.ALL.ADM3.subset, subset=species.co!="F_sp") ##FULL model with spatial administrative areas model.full_glm_spatial <- glm(POS_Both~species.co + Year + Year_bin + Museum + Nucleic.Ac + X260.280 + Month + SEX + Juvi. + NAME_3 , data=mydata.ALL.ADM3.subset, family=binomial(link="logit")) summary(model.full_glm_spatial) drop1(model.full_glm_spatial, test="Chisq") # > drop1(model.full_glm_spatial, test="Chisq") # Single term deletions # # Model: # POS_Both ~ species.co + Year + Year_bin + Museum + Nucleic.Ac + # X260.280 + Month + SEX + Juvi. + NAME_3 # Df Deviance AIC LRT Pr(>Chi) # 235.00 411.00 # species.co 4 243.37 411.37 8.373 0.078827 . # Year 1 235.53 409.53 0.535 0.464500 # Year_bin 13 255.29 405.29 20.292 0.088170 . # Museum 1 243.61 417.61 8.614 0.003336 ** # Nucleic.Ac 1 235.31 409.31 0.312 0.576254 # X260.280 1 235.12 409.12 0.120 0.728956 # Month 11 253.78 407.77 18.775 0.065252 . # SEX 1 240.06 414.06 5.057 0.024523 * # Juvi. 2 235.28 407.28 0.285 0.867179 # NAME_3 51 286.52 360.52 51.522 0.453241 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #model selection: glmulti (Comparison of AIC values from various models) library(glmulti) citation("glmulti") #best model: bestmod <- glm(POS_Both~species.co+Year_bin+Museum+SEX+Month + Year, data=mydata.ALL.ADM3.subset, family=binomial(link="logit")) summary(bestmod) # > summary(bestmod) # # Call: # glm(formula = POS_Both ~ species.co + Year_bin + Museum + SEX + # Month + Year, family = binomial(link = "logit"), data = mydata.ALL.ADM3.subset) # # Deviance Residuals: # Min 1Q Median 3Q Max # -1.4146 -0.4349 -0.1681 -0.0002 3.1722 # # Coefficients: # Estimate Std. Error z value Pr(>|z|) # (Intercept) 1.990e+02 1.759e+03 0.113 0.909926 # species.coF_ca -2.147e+00 8.170e-01 -2.628 0.008590 ** # species.coF_co 1.126e-02 4.486e-01 0.025 0.979973 # species.coF_lem -1.704e+01 2.365e+03 -0.007 0.994249 # species.coF_py -1.041e+00 5.130e-01 -2.030 0.042382 * # Year_bin1911-1915 1.414e+01 1.745e+03 0.008 0.993534 # Year_bin1916-1920 3.350e+01 2.939e+03 0.011 0.990905 # Year_bin1921-1925 1.573e+01 1.745e+03 0.009 0.992805 # Year_bin1926-1930 1.765e+01 1.745e+03 0.010 0.991927 # Year_bin1931-1935 1.786e+01 1.745e+03 0.010 0.991835 # Year_bin1936-1940 4.132e-01 2.799e+03 0.000 0.999882 # Year_bin1941-1945 1.703e+01 1.745e+03 0.010 0.992211 # Year_bin1945-1950 1.820e+01 1.745e+03 0.010 0.991676 # Year_bin1951-1955 1.833e+01 1.745e+03 0.011 0.991618 # Year_bin1956-1960 1.853e+01 1.745e+03 0.011 0.991527 # Year_bin1961-1965 1.957e+01 1.745e+03 0.011 0.991053 # Year_bin1966-1970 2.070e+01 1.745e+03 0.012 0.990532 # Year_bin1971-1975 4.084e+00 3.111e+03 0.001 0.998953 # Year_bin1991-1995 6.061e+01 1.115e+04 0.005 0.995662 # MuseumRMCA 4.396e+00 1.156e+00 3.803 0.000143 *** # SEXM -4.167e-01 3.240e-01 -1.286 0.198462 # Month2 -2.872e-01 7.203e-01 -0.399 0.690095 # Month3 -3.939e-01 6.739e-01 -0.584 0.558892 # Month4 1.230e-01 6.248e-01 0.197 0.843967 # Month5 5.755e-02 8.605e-01 0.067 0.946679 # Month6 2.618e-01 6.273e-01 0.417 0.676387 # Month7 -7.142e-01 6.061e-01 -1.178 0.238678 # Month8 -3.235e-02 6.552e-01 -0.049 0.960616 # Month9 -5.926e-01 6.728e-01 -0.881 0.378479 # Month10 -1.818e+01 1.206e+03 -0.015 0.987971 # Month11 3.491e-01 6.835e-01 0.511 0.609529 # Month12 -1.316e+00 8.555e-01 -1.539 0.123875 # Year -1.143e-01 1.184e-01 -0.965 0.334424 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # (Dispersion parameter for binomial family taken to be 1) # # Null deviance: 406.51 on 658 degrees of freedom # Residual deviance: 286.85 on 626 degrees of freedom # (240 observations deleted due to missingness) # AIC: 352.85 # # Number of Fisher Scoring iterations: 18 drop1(bestmod, test="Chisq") #drop one variable at a time (stepwise elimination) # > drop1(bestmod, test="Chisq") # Single term deletions # # Model: # POS_Both ~ species.co + Year_bin + Museum + SEX + Month + Year # Df Deviance AIC LRT Pr(>Chi) # 286.85 352.85 # species.co 4 301.62 359.62 14.766 0.005213 ** # Year_bin 14 308.44 346.44 21.585 0.087559 . # Museum 1 323.55 387.55 36.695 1.381e-09 *** # SEX 1 288.54 352.54 1.685 0.194290 # Month 11 306.02 350.02 19.167 0.058168 . # Year 1 287.79 351.79 0.938 0.332667 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 bestmod_dropyear <- glm(POS_Both~species.co+Year_bin+Museum+SEX+Month, data=mydata.ALL.ADM3.subset, family=binomial(link="logit")) summary(bestmod_dropyear) #bestmodel has dropped year variable (age of specimen) # > summary(bestmod) # # Call: # glm(formula = POS_Both ~ species.co + Year_bin + Museum + SEX + # Month, family = binomial(link = "logit"), data = mydata.ALL.ADM3.subset) # # Deviance Residuals: # Min 1Q Median 3Q Max # -1.3800 -0.4354 -0.1671 -0.0002 3.2144 # # Coefficients: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -1.908e+01 1.748e+03 -0.011 0.99129 # species.coF_ca -2.193e+00 8.202e-01 -2.673 0.00751 ** # species.coF_co 9.487e-02 4.381e-01 0.217 0.82859 # species.coF_lem -1.688e+01 2.317e+03 -0.007 0.99419 # species.coF_py -1.091e+00 5.077e-01 -2.148 0.03169 * # Year_bin1911-1915 1.356e+01 1.748e+03 0.008 0.99381 # Year_bin1916-1920 3.200e+01 2.903e+03 0.011 0.99120 # Year_bin1921-1925 1.406e+01 1.748e+03 0.008 0.99358 # Year_bin1926-1930 1.533e+01 1.748e+03 0.009 0.99300 # Year_bin1931-1935 1.499e+01 1.748e+03 0.009 0.99316 # Year_bin1936-1940 -3.146e+00 2.767e+03 -0.001 0.99909 # Year_bin1941-1945 1.296e+01 1.748e+03 0.007 0.99408 # Year_bin1945-1950 1.357e+01 1.748e+03 0.008 0.99380 # Year_bin1951-1955 1.329e+01 1.748e+03 0.008 0.99393 # Year_bin1956-1960 1.274e+01 1.748e+03 0.007 0.99419 # Year_bin1961-1965 1.334e+01 1.748e+03 0.008 0.99391 # Year_bin1966-1970 1.395e+01 1.748e+03 0.008 0.99363 # Year_bin1971-1975 -3.548e+00 3.070e+03 -0.001 0.99908 # Year_bin1991-1995 5.074e+01 1.114e+04 0.005 0.99637 # MuseumRMCA 4.556e+00 1.148e+00 3.967 7.28e-05 *** # SEXM -4.247e-01 3.230e-01 -1.315 0.18855 # Month2 -2.842e-01 7.209e-01 -0.394 0.69343 # Month3 -3.391e-01 6.709e-01 -0.505 0.61331 # Month4 6.283e-02 6.235e-01 0.101 0.91974 # Month5 1.071e-01 8.507e-01 0.126 0.89984 # Month6 2.336e-01 6.254e-01 0.374 0.70873 # Month7 -6.947e-01 6.031e-01 -1.152 0.24942 # Month8 -5.853e-02 6.547e-01 -0.089 0.92876 # Month9 -6.371e-01 6.749e-01 -0.944 0.34523 # Month10 -1.818e+01 1.196e+03 -0.015 0.98787 # Month11 3.584e-01 6.862e-01 0.522 0.60148 # Month12 -1.319e+00 8.543e-01 -1.544 0.12261 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # (Dispersion parameter for binomial family taken to be 1) # # Null deviance: 406.51 on 658 degrees of freedom # Residual deviance: 287.79 on 627 degrees of freedom # (240 observations deleted due to missingness) # AIC: 351.79 # # Number of Fisher Scoring iterations: 18 drop1(bestmod_dropyear, test="Chisq") #now see that sex should be dropped next # > drop1(bestmod, test="Chisq") # Single term deletions # # Model: # POS_Both ~ species.co + Year_bin + Museum + SEX + Month # Df Deviance AIC LRT Pr(>Chi) # 287.79 351.79 # species.co 4 303.70 359.70 15.912 0.00314 ** # Year_bin 14 312.54 348.54 24.749 0.03713 * # Museum 1 331.96 393.96 44.168 3.014e-11 *** # SEX 1 289.55 351.55 1.763 0.18426 # Month 11 306.52 348.52 18.724 0.06623 . # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 lrtest(bestmod_dropyear, bestmod) # > lrtest(bestmod_dropyear, bestmod) ##not significant so can drop this variable # Likelihood ratio test # # Model 1: POS_Both ~ species.co + Year_bin + Museum + SEX + Month # Model 2: POS_Both ~ species.co + Year_bin + Museum + SEX + Month + Year # #Df LogLik Df Chisq Pr(>Chisq) # 1 32 -143.90 # 2 33 -143.43 1 0.9385 0.3327 bestmod_dropsex <- glm(POS_Both~species.co+Year_bin+Museum+Month, data=mydata.ALL.ADM3.subset, family=binomial(link="logit")) summary(bestmod_dropsex) #model now without sex # > summary(bestmod_dropsex) #model now without sex # # Call: # glm(formula = POS_Both ~ species.co + Year_bin + Museum + Month, # family = binomial(link = "logit"), data = mydata.ALL.ADM3.subset) # # Deviance Residuals: # Min 1Q Median 3Q Max # -1.2833 -0.4413 -0.2156 -0.0707 3.2914 # # Coefficients: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -18.37358 1065.82651 -0.017 0.9862 # species.coF_ca -1.50040 0.66411 -2.259 0.0239 * # species.coF_co 0.44660 0.39209 1.139 0.2547 # species.coF_lem -1.17420 1.15002 -1.021 0.3072 # species.coF_py -0.96979 0.46238 -2.097 0.0360 * # Year_bin1911-1915 12.92212 1065.82661 0.012 0.9903 # Year_bin1916-1920 14.65027 1065.82760 0.014 0.9890 # Year_bin1921-1925 13.10553 1065.82660 0.012 0.9902 # Year_bin1926-1930 13.83442 1065.82675 0.013 0.9896 # Year_bin1931-1935 13.83421 1065.82672 0.013 0.9896 # Year_bin1936-1940 12.49906 1065.82688 0.012 0.9906 # Year_bin1941-1945 11.53418 1065.82689 0.011 0.9914 # Year_bin1945-1950 12.30111 1065.82670 0.012 0.9908 # Year_bin1951-1955 11.81385 1065.82682 0.011 0.9912 # Year_bin1956-1960 11.60573 1065.82664 0.011 0.9913 # Year_bin1961-1965 12.40690 1065.82668 0.012 0.9907 # Year_bin1966-1970 11.98226 1065.82706 0.011 0.9910 # Year_bin1971-1975 -3.60881 1913.57503 -0.002 0.9985 # Year_bin1981-1985 -4.64171 3105.63186 -0.001 0.9988 # Year_bin1991-1995 33.44831 6609.14534 0.005 0.9960 # MuseumRMCA 4.44922 1.06040 4.196 2.72e-05 *** # Month2 -0.31529 0.67634 -0.466 0.6411 # Month3 -0.50205 0.62186 -0.807 0.4195 # Month4 0.19708 0.57254 0.344 0.7307 # Month5 0.54186 0.71307 0.760 0.4473 # Month6 0.21632 0.56739 0.381 0.7030 # Month7 -0.73856 0.56919 -1.298 0.1944 # Month8 -0.27887 0.58650 -0.475 0.6344 # Month9 -0.11095 0.58012 -0.191 0.8483 # Month10 -2.38347 1.22191 -1.951 0.0511 . # Month11 0.03923 0.62810 0.062 0.9502 # Month12 -0.52980 0.65652 -0.807 0.4197 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # (Dispersion parameter for binomial family taken to be 1) # # Null deviance: 482.82 on 769 degrees of freedom # Residual deviance: 359.17 on 738 degrees of freedom # (172 observations deleted due to missingness) # AIC: 423.17 # # Number of Fisher Scoring iterations: 17 drop1(bestmod_dropsex, test="Chisq") ##see that month should be dropped next since now not significant # > drop1(bestmod_dropsex, test="Chisq") ##see that month should be dropped next since now not significant # Single term deletions # # Model: # POS_Both ~ species.co + Year_bin + Museum + Month # Df Deviance AIC LRT Pr(>Chi) # 359.17 423.17 # species.co 4 372.79 428.79 13.621 0.008607 ** # Year_bin 15 389.16 423.16 29.988 0.011964 * # Museum 1 412.41 474.41 53.234 2.96e-13 *** # Month 11 371.05 413.05 11.872 0.373311 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 lrtest(bestmod_dropsex, bestmod_dropyear) bestmod_dropmonth<- glm(POS_Both~species.co+Year_bin+Museum, data=mydata.ALL.ADM3.subset, family=binomial(link="logit")) summary(bestmod_dropmonth) #best model now with month dropped # > summary(bestmod_dropmonth) #best model now with month dropped # # Call: # glm(formula = POS_Both ~ species.co + Year_bin + Museum, family = binomial(link = "logit"), # data = mydata.ALL.ADM3.subset) # # Deviance Residuals: # Min 1Q Median 3Q Max # -1.0589 -0.4656 -0.2242 -0.0697 3.3482 # # Coefficients: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -6.0202 1.2205 -4.933 8.11e-07 *** # species.coF_ca -1.3964 0.6414 -2.177 0.0295 * # species.coF_co 0.5114 0.3133 1.632 0.1027 # species.coF_lem -0.4480 0.7309 -0.613 0.5399 # species.coF_py -0.9884 0.4212 -2.347 0.0189 * # Year_bin1899-1905 -17.4062 2657.0289 -0.007 0.9948 # Year_bin1906-1910 -13.0413 1025.7439 -0.013 0.9899 # Year_bin1911-1915 0.4187 0.7257 0.577 0.5640 # Year_bin1916-1920 0.3323 1.0574 0.314 0.7533 # Year_bin1921-1925 0.5427 0.6908 0.786 0.4320 # Year_bin1926-1930 0.3404 0.8284 0.411 0.6811 # Year_bin1931-1935 0.8010 0.8226 0.974 0.3301 # Year_bin1936-1940 -0.2174 0.7902 -0.275 0.7832 # Year_bin1941-1945 -1.2533 0.9947 -1.260 0.2077 # Year_bin1945-1950 -0.2312 0.7899 -0.293 0.7697 # Year_bin1951-1955 -0.9564 0.9896 -0.966 0.3338 # Year_bin1956-1960 -1.0849 0.7648 -1.419 0.1560 # Year_bin1961-1965 -0.1730 0.8194 -0.211 0.8328 # Year_bin1966-1970 -0.5408 1.2454 -0.434 0.6641 # Year_bin1971-1975 -15.8611 1667.9199 -0.010 0.9924 # Year_bin1981-1985 -16.9683 2917.0127 -0.006 0.9954 # Year_bin1991-1995 20.6119 6522.6387 0.003 0.9975 # MuseumRMCA 4.4225 1.0259 4.311 1.63e-05 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # (Dispersion parameter for binomial family taken to be 1) # # Null deviance: 580.19 on 941 degrees of freedom # Residual deviance: 454.04 on 919 degrees of freedom # AIC: 500.04 # # Number of Fisher Scoring iterations: 17 drop1(bestmod_dropmonth, test="Chisq") #see the final model # > drop1(bestmod_dropmonth, test="Chisq") #see the final model # Single term deletions # # Model: # POS_Both ~ species.co + Year_bin + Museum # Df Deviance AIC LRT Pr(>Chi) # 454.04 500.04 # species.co 4 471.68 509.68 17.643 0.001449 ** # Year_bin 17 491.17 503.17 37.134 0.003227 ** # Museum 1 526.01 570.01 71.970 < 2.2e-16 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 library(lmtest) lrtest(bestmod_dropmonth, bestmod_dropyear) ##Compare Tukeys" library(multcomp) summary(glht(bestmod_dropmonth, mcp(species.co="Tukey"))) # > summary(glht(bestmod_dropmonth, mcp(species.co="Tukey"))) # # Simultaneous Tests for General Linear Hypotheses # # Multiple Comparisons of Means: Tukey Contrasts # # # Fit: glm(formula = POS_Both ~ species.co + Year_bin + Museum, family = binomial(link = "logit"), # data = mydata.ALL.ADM3.subset) # # Linear Hypotheses: # Estimate Std. Error z value Pr(>|z|) # F_ca - F_an == 0 -1.3964 0.6414 -2.177 0.1694 # F_co - F_an == 0 0.5114 0.3133 1.632 0.4472 # F_lem - F_an == 0 -0.4480 0.7309 -0.613 0.9695 # F_py - F_an == 0 -0.9884 0.4212 -2.347 0.1159 # F_co - F_ca == 0 1.9078 0.6629 2.878 0.0282 * # F_lem - F_ca == 0 0.9484 0.9439 1.005 0.8375 # F_py - F_ca == 0 0.4080 0.7228 0.564 0.9774 # F_lem - F_co == 0 -0.9594 0.7353 -1.305 0.6625 # F_py - F_co == 0 -1.4998 0.4844 -3.096 0.0146 * # F_py - F_lem == 0 -0.5404 0.8169 -0.662 0.9598 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # (Adjusted p values reported -- single-step method) summary(glht(bestmod_dropmonth, mcp(Year_bin="Tukey"))) # > summary(glht(bestmod_dropmonth, mcp(Year_bin="Tukey"))) # # Simultaneous Tests for General Linear Hypotheses # # Multiple Comparisons of Means: Tukey Contrasts # # # Fit: glm(formula = POS_Both ~ species.co + Year_bin + Museum, family = binomial(link = "logit"), # data = mydata.ALL.ADM3.subset) # # Linear Hypotheses: # Estimate Std. Error z value Pr(>|z|) # 1899-1905 - == 0 -1.741e+01 2.657e+03 -0.007 1.0000 # 1906-1910 - == 0 -1.304e+01 1.026e+03 -0.013 1.0000 # 1911-1915 - == 0 4.187e-01 7.257e-01 0.577 1.0000 # 1916-1920 - == 0 3.323e-01 1.057e+00 0.314 1.0000 # 1921-1925 - == 0 5.427e-01 6.908e-01 0.786 1.0000 # 1926-1930 - == 0 3.404e-01 8.284e-01 0.411 1.0000 # 1931-1935 - == 0 8.010e-01 8.226e-01 0.974 0.9999 # 1936-1940 - == 0 -2.174e-01 7.902e-01 -0.275 1.0000 # 1941-1945 - == 0 -1.253e+00 9.947e-01 -1.260 0.9969 # 1945-1950 - == 0 -2.312e-01 7.899e-01 -0.293 1.0000 # 1951-1955 - == 0 -9.564e-01 9.896e-01 -0.966 0.9999 # 1956-1960 - == 0 -1.085e+00 7.648e-01 -1.419 0.9886 # 1961-1965 - == 0 -1.730e-01 8.194e-01 -0.211 1.0000 # 1966-1970 - == 0 -5.408e-01 1.245e+00 -0.434 1.0000 # 1971-1975 - == 0 -1.586e+01 1.668e+03 -0.010 1.0000 # 1981-1985 - == 0 -1.697e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - == 0 2.061e+01 6.523e+03 0.003 1.0000 # 1906-1910 - 1899-1905 == 0 4.365e+00 2.848e+03 0.002 1.0000 # 1911-1915 - 1899-1905 == 0 1.782e+01 2.657e+03 0.007 1.0000 # 1916-1920 - 1899-1905 == 0 1.774e+01 2.657e+03 0.007 1.0000 # 1921-1925 - 1899-1905 == 0 1.795e+01 2.657e+03 0.007 1.0000 # 1926-1930 - 1899-1905 == 0 1.775e+01 2.657e+03 0.007 1.0000 # 1931-1935 - 1899-1905 == 0 1.821e+01 2.657e+03 0.007 1.0000 # 1936-1940 - 1899-1905 == 0 1.719e+01 2.657e+03 0.006 1.0000 # 1941-1945 - 1899-1905 == 0 1.615e+01 2.657e+03 0.006 1.0000 # 1945-1950 - 1899-1905 == 0 1.717e+01 2.657e+03 0.006 1.0000 # 1951-1955 - 1899-1905 == 0 1.645e+01 2.657e+03 0.006 1.0000 # 1956-1960 - 1899-1905 == 0 1.632e+01 2.657e+03 0.006 1.0000 # 1961-1965 - 1899-1905 == 0 1.723e+01 2.657e+03 0.006 1.0000 # 1966-1970 - 1899-1905 == 0 1.687e+01 2.657e+03 0.006 1.0000 # 1971-1975 - 1899-1905 == 0 1.545e+00 3.137e+03 0.000 1.0000 # 1981-1985 - 1899-1905 == 0 4.379e-01 3.946e+03 0.000 1.0000 # 1991-1995 - 1899-1905 == 0 3.802e+01 7.043e+03 0.005 1.0000 # 1911-1915 - 1906-1910 == 0 1.346e+01 1.026e+03 0.013 1.0000 # 1916-1920 - 1906-1910 == 0 1.337e+01 1.026e+03 0.013 1.0000 # 1921-1925 - 1906-1910 == 0 1.358e+01 1.026e+03 0.013 1.0000 # 1926-1930 - 1906-1910 == 0 1.338e+01 1.026e+03 0.013 1.0000 # 1931-1935 - 1906-1910 == 0 1.384e+01 1.026e+03 0.013 1.0000 # 1936-1940 - 1906-1910 == 0 1.282e+01 1.026e+03 0.013 1.0000 # 1941-1945 - 1906-1910 == 0 1.179e+01 1.026e+03 0.011 1.0000 # 1945-1950 - 1906-1910 == 0 1.281e+01 1.026e+03 0.012 1.0000 # 1951-1955 - 1906-1910 == 0 1.208e+01 1.026e+03 0.012 1.0000 # 1956-1960 - 1906-1910 == 0 1.196e+01 1.026e+03 0.012 1.0000 # 1961-1965 - 1906-1910 == 0 1.287e+01 1.026e+03 0.013 1.0000 # 1966-1970 - 1906-1910 == 0 1.250e+01 1.026e+03 0.012 1.0000 # 1971-1975 - 1906-1910 == 0 -2.820e+00 1.958e+03 -0.001 1.0000 # 1981-1985 - 1906-1910 == 0 -3.927e+00 3.092e+03 -0.001 1.0000 # 1991-1995 - 1906-1910 == 0 3.365e+01 6.603e+03 0.005 1.0000 # 1916-1920 - 1911-1915 == 0 -8.640e-02 8.889e-01 -0.097 1.0000 # 1921-1925 - 1911-1915 == 0 1.240e-01 4.065e-01 0.305 1.0000 # 1926-1930 - 1911-1915 == 0 -7.826e-02 5.876e-01 -0.133 1.0000 # 1931-1935 - 1911-1915 == 0 3.823e-01 6.065e-01 0.630 1.0000 # 1936-1940 - 1911-1915 == 0 -6.361e-01 5.484e-01 -1.160 0.9989 # 1941-1945 - 1911-1915 == 0 -1.672e+00 8.442e-01 -1.981 0.8013 # 1945-1950 - 1911-1915 == 0 -6.499e-01 5.521e-01 -1.177 0.9987 # 1951-1955 - 1911-1915 == 0 -1.375e+00 7.917e-01 -1.737 0.9236 # 1956-1960 - 1911-1915 == 0 -1.504e+00 4.908e-01 -3.063 0.1095 # 1961-1965 - 1911-1915 == 0 -5.917e-01 5.616e-01 -1.054 0.9997 # 1966-1970 - 1911-1915 == 0 -9.595e-01 1.093e+00 -0.878 1.0000 # 1971-1975 - 1911-1915 == 0 -1.628e+01 1.668e+03 -0.010 1.0000 # 1981-1985 - 1911-1915 == 0 -1.739e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1911-1915 == 0 2.019e+01 6.523e+03 0.003 1.0000 # 1921-1925 - 1916-1920 == 0 2.104e-01 8.563e-01 0.246 1.0000 # 1926-1930 - 1916-1920 == 0 8.139e-03 9.842e-01 0.008 1.0000 # 1931-1935 - 1916-1920 == 0 4.687e-01 9.801e-01 0.478 1.0000 # 1936-1940 - 1916-1920 == 0 -5.497e-01 9.026e-01 -0.609 1.0000 # 1941-1945 - 1916-1920 == 0 -1.586e+00 1.124e+00 -1.411 0.9890 # 1945-1950 - 1916-1920 == 0 -5.635e-01 9.523e-01 -0.592 1.0000 # 1951-1955 - 1916-1920 == 0 -1.289e+00 1.123e+00 -1.147 0.9990 # 1956-1960 - 1916-1920 == 0 -1.417e+00 9.292e-01 -1.525 0.9758 # 1961-1965 - 1916-1920 == 0 -5.053e-01 9.758e-01 -0.518 1.0000 # 1966-1970 - 1916-1920 == 0 -8.731e-01 1.333e+00 -0.655 1.0000 # 1971-1975 - 1916-1920 == 0 -1.619e+01 1.668e+03 -0.010 1.0000 # 1981-1985 - 1916-1920 == 0 -1.730e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1916-1920 == 0 2.028e+01 6.523e+03 0.003 1.0000 # 1926-1930 - 1921-1925 == 0 -2.023e-01 5.698e-01 -0.355 1.0000 # 1931-1935 - 1921-1925 == 0 2.583e-01 5.621e-01 0.460 1.0000 # 1936-1940 - 1921-1925 == 0 -7.602e-01 5.100e-01 -1.490 0.9808 # 1941-1945 - 1921-1925 == 0 -1.796e+00 7.914e-01 -2.269 0.5890 # 1945-1950 - 1921-1925 == 0 -7.740e-01 5.153e-01 -1.502 0.9792 # 1951-1955 - 1921-1925 == 0 -1.499e+00 7.881e-01 -1.902 0.8481 # 1956-1960 - 1921-1925 == 0 -1.628e+00 4.751e-01 -3.426 0.0361 * # 1961-1965 - 1921-1925 == 0 -7.157e-01 5.576e-01 -1.284 0.9962 # 1966-1970 - 1921-1925 == 0 -1.084e+00 1.091e+00 -0.994 0.9999 # 1971-1975 - 1921-1925 == 0 -1.640e+01 1.668e+03 -0.010 1.0000 # 1981-1985 - 1921-1925 == 0 -1.751e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1921-1925 == 0 2.007e+01 6.523e+03 0.003 1.0000 # 1931-1935 - 1926-1930 == 0 4.606e-01 7.239e-01 0.636 1.0000 # 1936-1940 - 1926-1930 == 0 -5.579e-01 6.839e-01 -0.816 1.0000 # 1941-1945 - 1926-1930 == 0 -1.594e+00 9.259e-01 -1.721 0.9278 # 1945-1950 - 1926-1930 == 0 -5.717e-01 6.844e-01 -0.835 1.0000 # 1951-1955 - 1926-1930 == 0 -1.297e+00 8.951e-01 -1.449 0.9856 # 1956-1960 - 1926-1930 == 0 -1.425e+00 6.435e-01 -2.215 0.6305 # 1961-1965 - 1926-1930 == 0 -5.134e-01 7.005e-01 -0.733 1.0000 # 1966-1970 - 1926-1930 == 0 -8.813e-01 1.169e+00 -0.754 1.0000 # 1971-1975 - 1926-1930 == 0 -1.620e+01 1.668e+03 -0.010 1.0000 # 1981-1985 - 1926-1930 == 0 -1.731e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1926-1930 == 0 2.027e+01 6.523e+03 0.003 1.0000 # 1936-1940 - 1931-1935 == 0 -1.018e+00 6.817e-01 -1.494 0.9802 # 1941-1945 - 1931-1935 == 0 -2.054e+00 9.105e-01 -2.256 0.5982 # 1945-1950 - 1931-1935 == 0 -1.032e+00 6.786e-01 -1.521 0.9767 # 1951-1955 - 1931-1935 == 0 -1.757e+00 9.036e-01 -1.945 0.8229 # 1956-1960 - 1931-1935 == 0 -1.886e+00 6.516e-01 -2.895 0.1713 # 1961-1965 - 1931-1935 == 0 -9.740e-01 7.159e-01 -1.361 0.9926 # 1966-1970 - 1931-1935 == 0 -1.342e+00 1.178e+00 -1.139 0.9991 # 1971-1975 - 1931-1935 == 0 -1.666e+01 1.668e+03 -0.010 1.0000 # 1981-1985 - 1931-1935 == 0 -1.777e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1931-1935 == 0 1.981e+01 6.523e+03 0.003 1.0000 # 1941-1945 - 1936-1940 == 0 -1.036e+00 8.849e-01 -1.171 0.9987 # 1945-1950 - 1936-1940 == 0 -1.380e-02 6.392e-01 -0.022 1.0000 # 1951-1955 - 1936-1940 == 0 -7.389e-01 8.700e-01 -0.849 1.0000 # 1956-1960 - 1936-1940 == 0 -8.675e-01 6.030e-01 -1.439 0.9867 # 1961-1965 - 1936-1940 == 0 4.443e-02 6.695e-01 0.066 1.0000 # 1966-1970 - 1936-1940 == 0 -3.234e-01 1.149e+00 -0.281 1.0000 # 1971-1975 - 1936-1940 == 0 -1.564e+01 1.668e+03 -0.009 1.0000 # 1981-1985 - 1936-1940 == 0 -1.675e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1936-1940 == 0 2.083e+01 6.523e+03 0.003 1.0000 # 1945-1950 - 1941-1945 == 0 1.022e+00 8.855e-01 1.154 0.9989 # 1951-1955 - 1941-1945 == 0 2.969e-01 1.079e+00 0.275 1.0000 # 1956-1960 - 1941-1945 == 0 1.683e-01 8.761e-01 0.192 1.0000 # 1961-1965 - 1941-1945 == 0 1.080e+00 9.250e-01 1.168 0.9988 # 1966-1970 - 1941-1945 == 0 7.125e-01 1.312e+00 0.543 1.0000 # 1971-1975 - 1941-1945 == 0 -1.461e+01 1.668e+03 -0.009 1.0000 # 1981-1985 - 1941-1945 == 0 -1.572e+01 2.917e+03 -0.005 1.0000 # 1991-1995 - 1941-1945 == 0 2.187e+01 6.523e+03 0.003 1.0000 # 1951-1955 - 1945-1950 == 0 -7.251e-01 8.577e-01 -0.845 1.0000 # 1956-1960 - 1945-1950 == 0 -8.537e-01 5.979e-01 -1.428 0.9875 # 1961-1965 - 1945-1950 == 0 5.823e-02 6.685e-01 0.087 1.0000 # 1966-1970 - 1945-1950 == 0 -3.096e-01 1.139e+00 -0.272 1.0000 # 1971-1975 - 1945-1950 == 0 -1.563e+01 1.668e+03 -0.009 1.0000 # 1981-1985 - 1945-1950 == 0 -1.674e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1945-1950 == 0 2.084e+01 6.523e+03 0.003 1.0000 # 1956-1960 - 1951-1955 == 0 -1.286e-01 8.293e-01 -0.155 1.0000 # 1961-1965 - 1951-1955 == 0 7.834e-01 8.770e-01 0.893 1.0000 # 1966-1970 - 1951-1955 == 0 4.155e-01 1.271e+00 0.327 1.0000 # 1971-1975 - 1951-1955 == 0 -1.490e+01 1.668e+03 -0.009 1.0000 # 1981-1985 - 1951-1955 == 0 -1.601e+01 2.917e+03 -0.005 1.0000 # 1991-1995 - 1951-1955 == 0 2.157e+01 6.523e+03 0.003 1.0000 # 1961-1965 - 1956-1960 == 0 9.119e-01 6.209e-01 1.469 0.9834 # 1966-1970 - 1956-1960 == 0 5.441e-01 1.122e+00 0.485 1.0000 # 1971-1975 - 1956-1960 == 0 -1.478e+01 1.668e+03 -0.009 1.0000 # 1981-1985 - 1956-1960 == 0 -1.588e+01 2.917e+03 -0.005 1.0000 # 1991-1995 - 1956-1960 == 0 2.170e+01 6.523e+03 0.003 1.0000 # 1966-1970 - 1961-1965 == 0 -3.678e-01 1.156e+00 -0.318 1.0000 # 1971-1975 - 1961-1965 == 0 -1.569e+01 1.668e+03 -0.009 1.0000 # 1981-1985 - 1961-1965 == 0 -1.680e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1961-1965 == 0 2.078e+01 6.523e+03 0.003 1.0000 # 1971-1975 - 1966-1970 == 0 -1.532e+01 1.668e+03 -0.009 1.0000 # 1981-1985 - 1966-1970 == 0 -1.643e+01 2.917e+03 -0.006 1.0000 # 1991-1995 - 1966-1970 == 0 2.115e+01 6.523e+03 0.003 1.0000 # 1981-1985 - 1971-1975 == 0 -1.107e+00 3.360e+03 0.000 1.0000 # 1991-1995 - 1971-1975 == 0 3.647e+01 6.733e+03 0.005 1.0000 # 1991-1995 - 1981-1985 == 0 3.758e+01 7.145e+03 0.005 1.0000 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # (Adjusted p values reported -- single-step method) summary(glht(bestmod_dropmonth, mcp(Museum="Tukey"))) # > summary(glht(bestmod_dropmonth, mcp(Museum="Tukey"))) # # Simultaneous Tests for General Linear Hypotheses # # Multiple Comparisons of Means: Tukey Contrasts # # # Fit: glm(formula = POS_Both ~ species.co + Year_bin + Museum, family = binomial(link = "logit"), # data = mydata.ALL.ADM3.subset) # # Linear Hypotheses: # Estimate Std. Error z value Pr(>|z|) # RMCA - AMNH == 0 4.422 1.026 4.311 1.63e-05 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # (Adjusted p values reported -- single-step method) ### Bin with different years to make sure binning process has no effect on collection year significance mydata.ALL.AMD3_yrorder <- mydata.ALL.ADM3.subset[order(mydata.ALL.ADM3.subset$Year),] head(mydata.ALL.AMD3_yrorder) brk.pts <- seq(1898, 1993, len=20) brk.pts mydata.ALL.AMD3_yrorder$grp20 <- cut(mydata.ALL.AMD3_yrorder$Year, brk.pts, labels=F) mydata.ALL.AMD3_yrorder$grp20 <- as.factor(mydata.ALL.AMD3_yrorder$grp20) colnames(mydata.ALL.AMD3_yrorder) brk.pts <- seq(1898, 1993, len=10) brk.pts mydata.ALL.AMD3_yrorder$grp10 <- cut(mydata.ALL.AMD3_yrorder$Year, brk.pts, labels=F) mydata.ALL.AMD3_yrorder$grp10 <- as.factor(mydata.ALL.AMD3_yrorder$grp10) bestmod_grp10<- glm(POS_Both~species.co+grp10+Museum, data=mydata.ALL.AMD3_yrorder, family=binomial(link="logit")) summary(bestmod_grp10) drop1(bestmod_grp10, test="Chisq") summary(glht(bestmod_grp10, mcp(grp10="Tukey"))) # > brk.pts: [1] 1898.000 [2] 1908.556 [3] 1919.111 [4] 1929.667 [5] 1940.222 [6] 1950.778 [7] 1961.333 1971.889 1982.444 1993.000 # 6 - 2 == 0 -1.18905 0.41359 -2.875 0.0625 . ##1909-1919 vs. 1951-1961 # 6 - 3 == 0 -1.29626 0.38611 -3.357 0.0134 * # 1920-1929 vs. 1951-1961 bestmod_grp12<- glm(POS_Both~species.co+grp12+Museum, data=mydata.ALL.AMD3_yrorder, family=binomial(link="logit")) summary(bestmod_grp12) drop1(bestmod_grp12, test="Chisq") summary(glht(bestmod_grp12, mcp(grp12="Tukey"))) # > brk.pts # [1] 1898.000 [2]1906.636 [3] 1915.273 [4] 1923.909 1932.545 1941.182 [7] 1949.818 1958.455 1967.091 1975.727 1984.364 1993.000 # 7 - 3 == 0 -2.113e+00 5.470e-01 -3.863 <0.01 ** # 1916-1923 vs. 1950-1958 # 7 - 4 == 0 -1.782e+00 5.732e-01 -3.110 0.0414 * # 1924-1932 vs. 1950-1958 bestmod_grp13<- glm(POS_Both~species.co+grp13+Museum, data=mydata.ALL.AMD3_yrorder, family=binomial(link="logit")) summary(bestmod_grp13) drop1(bestmod_grp13, test="Chisq") summary(glht(bestmod_grp13, mcp(grp13="Tukey"))) # [1] 1898.000 1905.917 1913.833 [4] 1921.750 1929.667 1937.583 1945.500 [8] 1953.417 1961.333 1969.250 1977.167 1985.083 1993.000 # 8 - 4 == 0 -1.36874 0.43595 -3.140 0.0445 * #1922-1929 vs. 1954-1961 bestmod_grp15<- glm(POS_Both~species.co+grp15+Museum, data=mydata.ALL.AMD3_yrorder, family=binomial(link="logit")) summary(bestmod_grp15) drop1(bestmod_grp15, test="Chisq") summary(glht(bestmod_grp15, mcp(grp15="Tukey"))) # > brk.pts # [1] 1898.000 1904.786 1911.571 [4] 1918.357 [5] 1925.143 1931.929 1938.714 1945.500 [9] 1952.286 [10] 1959.071 1965.857 1972.643 1979.429 # [14] 1986.214 1993.000 # 9 - 4 == 0 -1.63020 0.53283 -3.059 0.070 . #1919-1925 vs. 1953-1959 bestmod_grp20<- glm(POS_Both~species.co+grp20+Museum, data=mydata.ALL.AMD3_yrorder, family=binomial(link="logit")) summary(bestmod_grp20) drop1(bestmod_grp20, test="Chisq") summary(glht(bestmod_grp20, mcp(grp20="Tukey"))) # > brk.pts # [1] 1898 1903 [3] 1908 1913 [5] 1918 1923 [7] 1928 1933 [9] 1938 1943 [11] 1948 1953 [13]1958 1963 [15]1968 1973 [17]1978 1983 [19]1988 1993 # 12 - 5 == 0 -2.17211 0.66280 -3.277 0.0593 . # 1918-1922 vs. 1953-1957 ######## (2) COMPARING HOST COMMUNITY COMPOSITION TO MPXV INFECTION ############### ############control for museum and collection period by including those as random variables, also offset by exposure variable to account for sample size ### ## Good hosts <- Fan + Fco only distributions ## PosHosts <- Fan, Fca, Fco, Flem, Fpy distributions ## PosHosts Historically <- found positive at some point <- Fan Fca, Fco Fis Flem Fpy Hgam H rufo ## Helio <- heliosciurus distributions ## Funi <- all funscurius distributions library(lmtest) mydata.yrADM3.museum <- read.csv("Yearbin_Museum_Locality_ADM3.csv") colnames(mydata.yrADM3.museum) logit.museum1 <- glmer(POS_Both ~ species.code + Museum + (1|Year_bin), data = mydata.mu.overlap.ALL, family=binomial) summary(logit.museum1) drop1(logit.museum1, test="Chisq") ## Comparison of F anerythrus to presence/absence other potential host species across an administrative area poisson_global_Fan1 <- glmer(F_an_POS ~ Fbamean + Fcamean + Fcomean + Fpymean + Funimean + Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) + (1|Museum), offset = (log(F_an_Tot)), na.action = "na.fail", data = mydata.yrADM3.museum, subset=F_an_Tot>0, family = poisson(link=log)) summary(poisson_global_Fan1) # > summary(poisson_global_Fan1) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] # Family: poisson ( log ) # Formula: F_an_POS ~ Fbamean + Fcamean + Fcomean + Fpymean + Funimean + # Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) + (1 | Museum) # Data: mydata.yrADM3.museum # Offset: (log(F_an_Tot)) # Subset: F_an_Tot > 0 # # AIC BIC logLik deviance df.resid # 134.6 162.3 -55.3 110.6 62 # # Scaled residuals: # Min 1Q Median 3Q Max # -1.1526 -0.4698 -0.3315 0.2107 2.4636 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 0.2564 0.5063 # Museum (Intercept) 0.9318 0.9653 # Number of obs: 74, groups: year_bin, 16; Museum, 2 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -1.9907 2.1304 -0.934 0.350 # Fbamean -2297.2830 18629.3678 -0.123 0.902 # Fcamean 3152.2141 27310.1252 0.115 0.908 # Fcomean 0.1467 3.5346 0.042 0.967 # Fpymean 3154.6384 27310.3442 0.116 0.908 # Funimean 2288.8039 18625.8635 0.123 0.902 # Heliomean 0.5846 3.8399 0.152 0.879 # goodmean 3152.1906 27308.7539 0.115 0.908 # pos_mean -5438.7897 45214.7885 -0.120 0.904 # pHistmean -2.7807 5.7299 -0.485 0.627 # # Correlation of Fixed Effects: # (Intr) Fbamen Fcamen Fcomen Fpymen Funimn Helimn goodmn pos_mn # Fbamean -0.317 # Fcamean 0.297 -0.935 # Fcomean -0.130 -0.513 0.480 # Fpymean 0.297 -0.935 1.000 0.480 # Funimean 0.317 -1.000 0.935 0.513 0.935 # Heliomean -0.213 0.101 -0.095 -0.185 -0.095 -0.101 # goodmean 0.297 -0.935 1.000 0.480 1.000 0.935 -0.095 # pos_mean -0.310 0.977 -0.989 -0.501 -0.989 -0.977 0.099 -0.989 # pHistmean -0.316 -0.075 0.070 0.577 0.070 0.075 -0.729 0.070 -0.073 poisson_modsel_Fan_mu <- dredge(poisson_global_Fan1, extra = c("R^2", F=function(x)summary(x)$fstatistic[[1]]), fixed = ~(1|year_bin)+(1|Museum), m.max = 2) summary(poisson_modsel_Fan_mu) poisson_modsel_Fan_mu plot(poisson_modsel_Fan_mu) ## Comparison of F congicus to presence/absence other potential host species across an administrative area poisson_global_Fco_mu <- glmer(F_co_POS ~ Fanmean + Fbamean + Fcamean + Fpymean + Funimean + Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) + (1|Museum), offset = (log(F_co_Tot)), na.action = "na.fail", data = mydata.yrADM3.museum, subset=F_co_Tot>0, family = poisson(link=log)) summary(poisson_global_Fco_mu) # > summary(poisson_global_Fco_mu) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] # Family: poisson ( log ) # Formula: F_co_POS ~ Fanmean + Fbamean + Fcamean + Fpymean + Funimean + # Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) + (1 | Museum) # Data: mydata.yrADM3.museum # Offset: (log(F_co_Tot)) # Subset: F_co_Tot > 0 # # AIC BIC logLik deviance df.resid # 95.9 117.0 -37.9 75.9 51 # # Scaled residuals: # Min 1Q Median 3Q Max # -1.12832 -0.49055 -0.08149 -0.00318 1.71067 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 0.1078 0.3284 # Museum (Intercept) 22.8106 4.7760 # Number of obs: 61, groups: year_bin, 14; Museum, 2 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -1.004e+01 6.843e+00 -1.468 0.142 # Fanmean -3.048e+00 4.999e+00 -0.610 0.542 # Fbamean -3.805e+02 3.025e+04 -0.013 0.990 # Fcamean -5.212e+02 7.118e+07 0.000 1.000 # Fpymean -3.774e+02 3.025e+04 -0.012 0.990 # Funimean 3.768e+02 3.025e+04 0.012 0.990 # Heliomean 3.899e+00 3.939e+00 0.990 0.322 # goodmean -3.733e+02 3.025e+04 -0.012 0.990 # # Correlation of Fixed Effects: # (Intr) Fanmen Fbamen Fcamen Fpymen Funimn Helimn # Fanmean 0.585 # Fbamean -0.433 0.021 # Fcamean 0.000 0.000 0.000 # Fpymean -0.433 0.021 1.000 0.000 # Funimean 0.433 -0.021 -1.000 0.000 -1.000 # Heliomean -0.820 -0.521 0.602 0.000 0.602 -0.602 # goodmean -0.433 0.021 1.000 0.000 1.000 -1.000 0.602 poisson_modsel_Fco_mu <- dredge(poisson_global_Fco_mu, extra = c("R^2", F=function(x)summary(x)$fstatistic[[1]]), fixed = ~(1|year_bin)+(1|Museum), m.max = 2) summary(poisson_modsel_Fco_mu) poisson_modsel_Fco_mu plot(poisson_modsel_Fco_mu) poisson_global_Fco_Nomu <- glmer(F_co_POS ~ Fanmean + Fbamean + Fcamean + Fpymean + Funimean + Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin), offset = (log(F_co_Tot)), na.action = "na.fail", data = mydata.yrADM3.museum, subset=F_co_Tot>0, family = poisson(link=log)) summary(poisson_global_Fco_Nomu) poisson_modsel_Fco_Nomu <- dredge(poisson_global_Fco_Nomu, extra = c("R^2", F=function(x)summary(x)$fstatistic[[1]]), fixed = ~(1|year_bin), m.max = 1) summary(poisson_modsel_Fco_Nomu) poisson_modsel_Fco_Nomu plot(poisson_modsel_Fco_mu) ## For all of F. congicus compared to F an poisson_Fco_mu <- glmer(F_co_POS ~ Fanmean + (1 | year_bin), offset = (log(F_co_Tot)), na.action = "na.fail", data = mydata.yrADM3.museum, subset=F_co_Tot>0, family = poisson(link=log)) summary(poisson_Fco_mu) # > summary(poisson_Fco_mu) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] # Family: poisson ( log ) # Formula: F_co_POS ~ Fanmean + (1 | year_bin) # Data: mydata.yrADM3.museum # Offset: (log(F_co_Tot)) # Subset: F_co_Tot > 0 # # AIC BIC logLik deviance df.resid # 95.2 101.6 -44.6 89.2 58 # # Scaled residuals: # Min 1Q Median 3Q Max # -1.1634 -0.4292 -0.3073 -0.1356 1.8465 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 1.798 1.341 # Number of obs: 61, groups: year_bin, 14 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -4.4240 0.9699 -4.561 5.08e-06 *** # Fanmean 2.9129 0.8584 3.393 0.00069 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Correlation of Fixed Effects: # (Intr) # Fanmean -0.848 anova(poisson_Fco_mu) # > anova(poisson_Fco_mu) # Analysis of Variance Table # Df Sum Sq Mean Sq F value # Fanmean 1 15.999 15.999 15.999 drop1(poisson_Fco_mu, test="Chisq") # > drop1(poisson_Fco_mu, test="Chisq") # Single term deletions # # Model: # F_co_POS ~ Fanmean + (1 | year_bin) # Df AIC LRT Pr(Chi) # 95.249 # Fanmean 1 114.821 21.572 3.408e-06 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 options(na.action = "na.fail") library(MuMIn) poisson_global1_Fco_mu <- glmer(F_co_POS ~ Fanmean + Fbamean + Fcamean + Fpymean + Funimean + Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) , offset = (log(F_co_Tot)), na.action = "na.fail", data = mydata.yrADM3.museum, subset=F_co_Tot>0, family = poisson(link=log)) poisson_modsel_Fco_mu <- dredge(poisson_global1_Fco_mu, extra = c("R^2", F=function(x)summary(x)$fstatistic[[1]]), fixed = ~(1|year_bin)+(1|Museum), m.max = 2) summary(poisson_modsel_Fco_mu) poisson_modsel_Fco_mu plot(poisson_modsel_Fco_mu) # Model selection table # (Int) Fanmn Fbm Fcm Fpy Funmn Hlm pos_men R^2 df logLik AICc delta weight # 3 -4.424 2.913 0.4306 3 -44.178 94.8 0.00 0.141 # 35 -2.711 5.917 -2.35200 0.4508 4 -43.093 94.9 0.13 0.132 # 7 -4.216 2.712 -3.504 0.4385 4 -43.757 96.2 1.46 0.068 # 515 -3.445 5.070 -1.567 0.4379 4 -43.788 96.3 1.52 0.066 # 4 -3.767 3.427 0.4333 4 -44.035 96.8 2.01 0.051 # 19 -4.410 2.949 -0.83760 0.4328 4 -44.060 96.8 2.06 0.050 # 131 -4.559 3.021 0.3835 0.4320 4 -44.103 96.9 2.15 0.048 # 73 -4.368 -3.02100 0.4306 4 -44.174 97.1 2.29 0.045 # 11 -4.368 2.935 -0.08576 0.4306 4 -44.174 97.1 2.29 0.045 # 67 -4.368 3.021 0.4306 4 -44.174 97.1 2.29 0.045 # 259 -4.417 2.920 0.4306 4 -44.178 97.1 2.30 0.045 # 513 -5.796 2.122 0.3981 3 -45.844 98.1 3.33 0.027 # 65 -5.526 0.3951 3 -45.991 98.4 3.63 0.023 # 193 -6.822 1.8310 0.4121 4 -45.133 99.0 4.21 0.017 # 321 -6.543 0.4114 4 -45.171 99.1 4.28 0.017 # 545 -5.570 -3.13900 5.152 0.4045 4 -45.520 99.8 4.98 0.012 # 517 -5.570 -3.137 2.013 0.4045 4 -45.521 99.8 4.98 0.012 # 37 -5.570 -5.150 2.01300 0.4045 4 -45.521 99.8 4.98 0.012 model.avg(poisson_modsel_Fco_mu, beta=FALSE, rank = "AICc", fit=TRUE, subset = cumsum(weight) <= .95) model.avg(poisson_modsel_Fco_mu, beta = FALSE, rank = "AICc",subset = delta<5) ?model.avg models_Fco<- get.models(poisson_modsel_Fco_mu, subset = 1:10) summary(model.avg(models_Fco)) #F congicus if compared to F anerythrus only for the RMCA specimens poisson_Fco_no_muRMCA <- glmer(F_co_POS ~ Fanmean + (1 | year_bin), offset = (log(F_co_Tot)), na.action = "na.fail", data = mydata.yrADM3.museum, subset=F_co_Tot>0 & Museum =="RMCA", family = poisson(link=log)) drop1(poisson_Fco_no_muRMCA, test="Chisq") # > drop1(poisson_Fco_no_muRMCA, test="Chisq") # Single term deletions # # Model: # F_co_POS ~ Fanmean + (1 | year_bin) # Df AIC LRT Pr(Chi) # 78.530 # Fanmean 1 76.538 0.0081152 0.9282 ##Comparison of F. car vs. other host species presence/absence poisson_global_Fca_mu <- glmer(F_ca_POS ~ Fanmean + Fbamean + Fcomean + Fpymean + Flemmean + Funimean + Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) + (1|Museum), offset = (log(F_ca_Tot)), data = mydata.yrADM3.museum, subset=F_ca_Tot>0, na.action = "na.fail", family = poisson(link=log)) summary(poisson_global_Fca_mu) # #> summary(poisson_global_Fca_mu) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] # Family: poisson ( log ) # Formula: F_ca_POS ~ Fanmean + goodmean + pos_mean + ++Funimean + Heliomean + # Fpymean + Heliomean + (1 | year_bin) + (1 | Museum) # Data: mydata.yrADM3.museum # Offset: (log(F_ca_Tot)) # Subset: F_ca_Tot > 0 # # AIC BIC logLik deviance df.resid # 28.4 41.0 -6.2 12.4 28 # # Scaled residuals: # Min 1Q Median 3Q Max # -0.62903 -0.17939 -0.08462 -0.01851 2.99630 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 0 0 # Museum (Intercept) 0 0 # Number of obs: 36, groups: year_bin, 10; Museum, 2 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -1.167 2.567 -0.5 0.649 # Fanmean 4.338 9.696 0.4 0.655 # pos_mean 43453.578 21.673 2005.0 <2e-16 *** # Funimean -43455.904 22.016 -1973.9 <2e-16 *** # Heliomean -3.404 6.170 -0.6 0.581 # Fpymean 4.642 7.687 0.6 0.546 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Correlation of Fixed Effects: # (Intr) Fanmen pos_mn Funimn Helimn # Fanmean -0.855 # pos_mean 0.110 -0.120 # Funimean 0.176 -0.195 -0.935 # Heliomean -0.907 0.962 -0.130 -0.209 # Fpymean -0.160 0.075 -0.074 -0.118 0.253 poisson_modsel_Fca_mu <- dredge(poisson_global_Fca_mu, extra = c("R^2", F=function(x)summary(x)$fstatistic[[1]]), fixed = ~(1|year_bin)+(1|Museum), m.max = 2) poisson_modsel_Fca_mu plot(poisson_modsel_Fca_mu) models_Fca<- get.models(poisson_modsel_Fca_mu, subset = 1:2) summary(model.avg(models_Fca)) drop1(poisson_Fco_no_muRMCA, test="Chisq") poisson_Fca_mu1 <- glmer(F_ca_POS ~ Funimean + pos_mean + (1 | year_bin) + (1|Museum), offset = (log(F_ca_Tot)), data = mydata.yrADM3.museum, subset=F_ca_Tot>0, na.action = "na.fail", family = poisson(link=log)) summary(poisson_Fca_mu1) # > summary(poisson_Fca_mu1) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] # Family: poisson ( log ) # Formula: F_ca_POS ~ Funimean + pos_mean + (1 | year_bin) + (1 | Museum) # Data: mydata.yrADM3.museum # Offset: (log(F_ca_Tot)) # Subset: F_ca_Tot > 0 # # AIC BIC logLik deviance df.resid # 26.5 34.5 -8.3 16.5 31 # # Scaled residuals: # Min 1Q Median 3Q Max # -0.5214 -0.2306 -0.1854 -0.1276 4.3136 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 0 0 # Museum (Intercept) 0 0 # Number of obs: 36, groups: year_bin, 10; Museum, 2 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -3.207 1.130 -2.84 0.00455 ** # Funimean -16374.542 52.582 -311.41 < 2e-16 *** # pos_mean 16374.011 52.579 311.42 < 2e-16 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Correlation of Fixed Effects: # (Intr) Funimn # Funimean -0.006 # pos_mean -0.006 -1.000 drop1(poisson_Fca_mu1, test="Chisq") # > drop1(poisson_Fca_mu1, test="Chisq") # Single term deletions # # Model: # F_ca_POS ~ Funimean + pos_mean + (1 | year_bin) + (1 | Museum) # Df AIC LRT Pr(Chi) # 26.548 # Funimean 1 28.377 3.8288 0.05038 . # pos_mean 1 28.377 3.8286 0.05039 . # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 colnames(mydata.yrADM3.museum) poisson_global_Flem_mu <- glmer(F_lem_P ~ Fanmean + Fbamean + Fcomean + Fpymean + Funimean + Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) + (1|Museum), offset = (log(F_lem_T)), data = mydata.yrADM3.museum, subset=F_lem_T>0, na.action = "na.fail", family = poisson(link=log)) summary(poisson_global_Flem_mu) # > summary(poisson_global_Flem_mu) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] # Family: poisson ( log ) # Formula: F_lem_P ~ Fanmean + pos_mean + Allspmean + (1 | year_bin) + (1 | Museum) # Data: mydata.yrADM3.museum # Offset: (log(F_lem_T)) # Subset: F_lem_T > 0 # # AIC BIC logLik deviance df.resid # 26.0 32.8 -7.0 14.0 17 # # Scaled residuals: # Min 1Q Median 3Q Max # -0.8156 -0.2366 0.0000 0.0000 1.3441 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 0 0 # Museum (Intercept) 0 0 # Number of obs: 23, groups: year_bin, 10; Museum, 2 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) 1.700e+00 8.068e+00 0.211 0.833 # Fanmean 4.160e+00 8.143e+00 0.511 0.609 # pos_mean 2.804e+05 1.892e+05 1.482 0.138 # Allspmean -2.804e+05 1.892e+05 -1.482 0.138 # # Correlation of Fixed Effects: # (Intr) Fanmen pos_mn # Fanmean 0.976 # pos_mean -0.004 -0.063 # Allspmean 0.004 0.063 -1.000 drop1(poisson_global_Flem_mu, test="Chisq") # > drop1(poisson_global_Flem_mu, test="Chisq") # Single term deletions # # Model: # F_lem_P ~ Fanmean + pos_mean + Allspmean + (1 | year_bin) + (1 | # Museum) # Df AIC LRT Pr(Chi) # 25.973 # Fanmean 1 25.169 1.1956 0.27421 # pos_mean 1 25.924 1.9511 0.16247 # Allspmean 1 30.190 6.2171 0.01265 * # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 poisson_global_Fpy_mu <- glmer(F_py_POS ~ Fanmean + Fbamean + Fcomean + Flemmean + Funimean + Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) + (1|Museum), offset = (log(F_py_Tot)), data = mydata.yrADM3.museum, subset=F_py_Tot>0, na.action = "na.fail", family = poisson(link=log)) summary(poisson_global_Fpy_mu) # > summary(poisson_global_Fpy_mu) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] # Family: poisson ( log ) # Formula: F_py_POS ~ Fanmean + Fbamean + Fcomean + Flemmean + Funimean + # Heliomean + Allspmean + goodmean + pos_mean + pHistmean + (1 | year_bin) + (1 | Museum) # Data: mydata.yrADM3.museum # Offset: (log(F_py_Tot)) # Subset: F_py_Tot > 0 # # AIC BIC logLik deviance df.resid # 55.9 77.1 -16.9 33.9 40 # # Scaled residuals: # Min 1Q Median 3Q Max # -0.8463 -0.2815 -0.1661 0.0000 4.0212 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 3.712e-10 1.927e-05 # Museum (Intercept) 0.000e+00 0.000e+00 # Number of obs: 51, groups: year_bin, 12; Museum, 2 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -2.286e+00 2.822e+00 -1 0.418 # Fanmean 7.595e-01 4.971e+00 0 0.879 # Fbamean 1.367e+05 1.448e+03 94 <2e-16 *** # Fcomean -4.590e+01 1.235e+03 0 0.970 # Flemmean -2.348e+01 2.139e+03 0 0.991 # Funimean -1.367e+05 1.202e+01 -11370 <2e-16 *** # Heliomean 5.456e-02 2.763e+00 0 0.984 # pos_mean 1.367e+05 1.175e+01 11634 <2e-16 *** # pHistmean -4.029e+00 2.656e+00 -2 0.129 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Correlation of Fixed Effects: # (Intr) Fanmen Fbamen Fcomen Flemmn Funimn Helimn pos_mn # Fanmean -0.699 # Fbamean 0.001 -0.001 # Fcomean 0.001 -0.001 0.000 # Flemmean -0.001 0.000 0.000 -0.289 # Funimean 0.168 -0.102 0.000 0.003 -0.002 # Heliomean -0.770 0.863 -0.001 -0.001 0.000 -0.120 # pos_mean 0.056 -0.034 0.000 -0.003 0.002 -0.955 -0.040 # pHistmean -0.300 -0.276 0.000 0.000 0.001 -0.158 -0.173 -0.053 drop1(poisson_global_Fpy_mu, test="Chisq") #### ONly looking at areas where museums overlap mydata.mu.overlap <- rbind(subset(mydata.yrADM3.museum, subset=NAME_3=="Bafwasende"), subset(mydata.yrADM3.museum, subset=NAME_3=="Beni"), subset(mydata.yrADM3.museum, subset=NAME_3=="Fizi"), subset(mydata.yrADM3.museum, subset=NAME_3=="Kabare"), subset(mydata.yrADM3.museum, subset=NAME_3=="Kazumba"), subset(mydata.yrADM3.museum, subset=NAME_3=="Kinshasa Urban"), subset(mydata.yrADM3.museum, subset=NAME_3=="Lukolela"), subset(mydata.yrADM3.museum, subset=NAME_3=="Mambasa"), subset(mydata.yrADM3.museum, subset=NAME_3=="Polo"), subset(mydata.yrADM3.museum, subset=NAME_3=="Rungu"), subset(mydata.yrADM3.museum, subset=NAME_3=="Rutshuru"), subset(mydata.yrADM3.museum, subset=NAME_3=="Walikale")) museum_Fan <- glmer(F_an_POS ~ Museum + (1|year_bin), offset = (log(F_an_Tot)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_an_Tot>0, family = poisson(link=log)) summary(museum_Fan) drop1(museum_Fan, test="Chisq") museum_Fca <- glmer(F_ca_POS ~ Museum + (1|year_bin), offset = (log(F_ca_Tot)), na.action = "na.omit", data = mydata.mu.overlap, subset=F_ca_Tot>0, family = poisson(link=log)) summary(museum_Fca) drop1(museum_Fca, test="Chisq") museum_Fco <- glmer(F_co_POS ~ Museum + (1|year_bin), offset = (log(F_co_Tot)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_co_Tot>0, family = poisson(link=log)) summary(museum_Fco) drop1(museum_Fco, test="Chisq") colnames(mydata.mu.overlap) museum_Flem <- glmer(F_lem_P ~ Museum + (1|year_bin), offset = (log(F_lem_T)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_lem_T>0, family = poisson(link=log)) summary(museum_Flem) drop1(museum_Flem, test="Chisq") museum_Fpy <- glmer(F_py_POS ~ Museum + (1|year_bin), offset = (log(F_py_Tot)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_py_Tot>0, family = poisson(link=log)) summary(museum_Fpy) drop1(museum_Fpy, test="Chisq") # > summary(museum_Fan) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [glmerMod # ] # Family: poisson ( log ) # Formula: F_an_POS ~ Museum + (1 | year_bin) # Data: mydata.mu.overlap # Offset: (log(F_an_Tot)) # Subset: F_an_Tot > 0 # # AIC BIC logLik deviance df.resid # 43.3 46.8 -18.7 37.3 21 # # Scaled residuals: # Min 1Q Median 3Q Max # -1.1414 -0.5724 -0.2887 0.4847 1.6615 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 0 0 # Number of obs: 24, groups: year_bin, 9 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -4.094 1.000 -4.094 4.23e-05 *** # MuseumRMCA 2.285 1.026 2.227 0.0259 * # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Correlation of Fixed Effects: # (Intr) # MuseumRMCA -0.975 # > drop1(museum_Fan, test="Chisq") # Single term deletions # # Model: # F_an_POS ~ Museum + (1 | year_bin) # Df AIC LRT Pr(Chi) # 43.300 # Museum 1 51.354 10.054 0.00152 ** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # > summary(museum_Fco) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [glmerMod # ] # Family: poisson ( log ) # Formula: F_co_POS ~ Museum + (1 | year_bin) # Data: mydata.mu.overlap # Offset: (log(F_co_Tot)) # Subset: F_co_Tot > 0 # # AIC BIC logLik deviance df.resid # 21.1 22.0 -7.5 15.1 7 # # Scaled residuals: # Min 1Q Median 3Q Max # -0.61769 -0.43475 -0.21739 -0.00001 1.20787 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 0.2813 0.5304 # Number of obs: 10, groups: year_bin, 8 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -23.51 34348.56 -0.001 0.999 # MuseumRMCA 21.89 34348.56 0.001 0.999 # # Correlation of Fixed Effects: # (Intr) # MuseumRMCA -1.000 # # Single term deletions # # Model: # F_co_POS ~ Museum + (1 | year_bin) # Df AIC LRT Pr(Chi) # 21.096 # Museum 1 23.071 3.9748 0.04619 * # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # > museum_Fpy <- glmer(F_py_POS ~ Museum + (1|year_bin), offset = (log(F_py_Tot)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_py_Tot>0, family = poisson(link=log)) # > summary(museum_Fpy) # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [glmerMod # ] # Family: poisson ( log ) # Formula: F_py_POS ~ Museum + (1 | year_bin) # Data: mydata.mu.overlap # Offset: (log(F_py_Tot)) # Subset: F_py_Tot > 0 # # AIC BIC logLik deviance df.resid # 28.0 30.7 -11.0 22.0 15 # # Scaled residuals: # Min 1Q Median 3Q Max # -0.76631 -0.39385 -0.00817 -0.00001 2.92963 # # Random effects: # Groups Name Variance Std.Dev. # year_bin (Intercept) 0.07887 0.2808 # Number of obs: 18, groups: year_bin, 7 # # Fixed effects: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -23.90146 0.02196 -1088.4 <2e-16 *** # MuseumRMCA 21.28272 0.02196 969.1 <2e-16 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Correlation of Fixed Effects: # (Intr) # MuseumRMCA -0.251 # > drop1(museum_Fpy, test="Chisq") # Single term deletions # # Model: # F_py_POS ~ Museum + (1 | year_bin) # Df AIC LRT Pr(Chi) # 28.031 # Museum 1 29.041 3.0106 0.08272 . # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 ##### JUST in museum specimens from Zaire/DRC # > summary(logit_museum) # # Call: # glm(formula = POS_Both ~ Museum, family = binomial, data = mydata.DRC, # subset = species.code == "F_an", na.action = na.omit) # # Deviance Residuals: # Min 1Q Median 3Q Max # -0.5780 -0.5780 -0.5780 -0.1865 2.8497 # # Coefficients: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -4.043 1.009 -4.009 6.11e-05 *** # MuseumRMCA 2.338 1.022 2.287 0.0222 * # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # (Dispersion parameter for binomial family taken to be 1) # # Null deviance: 255.67 on 330 degrees of freedom # Residual deviance: 244.51 on 329 degrees of freedom # AIC: 248.51 # # Number of Fisher Scoring iterations: 6 # # > drop1(logit_museum, test="Chisq") # Single term deletions # # Model: # POS_Both ~ Museum # Df Deviance AIC LRT Pr(>Chi) # 244.51 248.51 # Museum 1 255.67 257.67 11.16 0.0008358 *** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # > logit_museum <- glm(POS_Both~Museum, data=mydata.DRC, subset=species.code=="F_co", family=binomial, na.action=na.omit) # > summary(logit_museum) # # Call: # glm(formula = POS_Both ~ Museum, family = binomial, data = mydata.DRC, # subset = species.code == "F_co", na.action = na.omit) # # Deviance Residuals: # Min 1Q Median 3Q Max # -0.75853 -0.75853 -0.75853 -0.00022 1.66511 # # Coefficients: # Estimate Std. Error z value Pr(>|z|) # (Intercept) -17.57 1142.05 -0.015 0.988 # MuseumRMCA 16.47 1142.05 0.014 0.988 # # (Dispersion parameter for binomial family taken to be 1) # # Null deviance: 136.98 on 127 degrees of freedom # Residual deviance: 130.46 on 126 degrees of freedom # AIC: 134.46 # # Number of Fisher Scoring iterations: 16 # # > drop1(logit_museum, test="Chisq") # Single term deletions # # Model: # POS_Both ~ Museum # Df Deviance AIC LRT Pr(>Chi) # 130.46 134.46 # Museum 1 136.98 138.98 6.5211 0.01066 * # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 ### Comparison of Positives for various species by museum (fixed variable) and collection period (random effect) get data where overlap in ADM3 administrative area: mydata.mu.overlap <- rbind(subset(mydata.yrADM3.museum, subset=NAME_3=="Bafwasende"), subset(mydata.yrADM3.museum, subset=NAME_3=="Beni"), subset(mydata.yrADM3.museum, subset=NAME_3=="Fizi"), subset(mydata.yrADM3.museum, subset=NAME_3=="Kabare"), subset(mydata.yrADM3.museum, subset=NAME_3=="Kazumba"), subset(mydata.yrADM3.museum, subset=NAME_3=="Kinshasa Urban"), subset(mydata.yrADM3.museum, subset=NAME_3=="Lukolela"), subset(mydata.yrADM3.museum, subset=NAME_3=="Mambasa"), subset(mydata.yrADM3.museum, subset=NAME_3=="Polo"), subset(mydata.yrADM3.museum, subset=NAME_3=="Rungu"), subset(mydata.yrADM3.museum, subset=NAME_3=="Rutshuru"), subset(mydata.yrADM3.museum, subset=NAME_3=="Walikale")) ### Include only administrative areas where there is overlap in specimens from both museums mydata.mu.overlap museum_Fan <- glmer(F_an_POS ~ Museum + (1|year_bin), offset = (log(F_an_Tot)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_an_Tot>0, family = poisson(link=log)) drop1(museum_Fan, test="Chisq") # > drop1(museum_Fan, test="Chisq") # Single term deletions # # Model: # F_an_POS ~ Museum + (1 | year_bin) # Df AIC LRT Pr(Chi) # 43.300 # Museum 1 51.354 10.054 0.00152 ** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 museum_Fca <- glmer(F_ca_POS ~ Museum + (1|year_bin), offset = (log(F_ca_Tot)), na.action = "na.omit", data = mydata.mu.overlap, subset=F_ca_Tot>0, family = poisson(link=log)) summary(museum_Fca) drop1(museum_Fca, test="Chisq") museum_Fco <- glmer(F_co_POS ~ Museum + (1|year_bin), offset = (log(F_co_Tot)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_co_Tot>0, family = poisson(link=log)) summary(museum_Fco) drop1(museum_Fco, test="Chisq") # > drop1(museum_Fco, test="Chisq") # Single term deletions # # Model: # F_co_POS ~ Museum + (1 | year_bin) # Df AIC LRT Pr(Chi) # 21.096 # Museum 1 23.071 3.9748 0.04619 * # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 colnames(mydata.mu.overlap) museum_Flem <- glmer(F_lem_P ~ Museum + (1|year_bin), offset = (log(F_lem_T)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_lem_T>0, family = poisson(link=log)) summary(museum_Flem) drop1(museum_Flem, test="Chisq") museum_Fpy <- glmer(F_py_POS ~ Museum + (1|year_bin), offset = (log(F_py_Tot)), na.action = "na.fail", data = mydata.mu.overlap, subset=F_py_Tot>0, family = poisson(link=log)) summary(museum_Fpy) drop1(museum_Fpy, test="Chisq") ###Comparison of DNA quality/concentration with museum: mydata.ALL <- read.csv('allsamples_binnedyear.csv', sep=',',header=T) #read in csv file colnames(mydata.ALL) ?glm museum_qual <- glm(X260.280~Museum, data=mydata.ALL, na.action=na.omit) summary(museum_qual) # > summary(museum_qual) # # Call: # glm(formula = X260.280 ~ Museum, data = mydata.ALL, na.action = na.omit) # # Deviance Residuals: # Min 1Q Median 3Q Max # -0.6740 -0.1286 0.0060 0.1060 7.1914 # # Coefficients: # Estimate Std. Error t value Pr(>|t|) # (Intercept) 1.72401 0.01958 88.043 <2e-16 *** # MuseumRMCA 0.04456 0.02303 1.935 0.0533 . # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # (Dispersion parameter for gaussian family taken to be 0.1004584) # # Null deviance: 95.209 on 945 degrees of freedom # Residual deviance: 94.833 on 944 degrees of freedom # (35 observations deleted due to missingness) # AIC: 514.71 # # Number of Fisher Scoring iterations: 2 museum_qual glm_conc_museum <- glm(Nucleic.Ac~Museum, data=mydata.ALL, na.action=na.omit) summary(glm_conc_museum) # > summary(glm_conc_museum) # # Call: # glm(formula = Nucleic.Ac ~ Museum, data = mydata.ALL, na.action = na.omit) # # Deviance Residuals: # Min 1Q Median 3Q Max # -87.96 -46.03 -28.86 18.69 585.74 # # Coefficients: # Estimate Std. Error t value Pr(>|t|) # (Intercept) 54.453 4.980 10.935 < 2e-16 *** # MuseumRMCA 15.504 5.856 2.647 0.00825 ** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # (Dispersion parameter for gaussian family taken to be 6496.948) # # Null deviance: 6178653 on 945 degrees of freedom # Residual deviance: 6133119 on 944 degrees of freedom # (35 observations deleted due to missingness) # AIC: 10994 # # Number of Fisher Scoring iterations: 2 #######ANOVA: difference by DNA concentration or quality??? ########## head(mydata.ALL) mylogit.DNAconc <- glm(POS_Both ~ Nucleic.Acid.Conc.Nanodrop..ng.µl., data=mydata.ALL, family=poisson(link=log)) summary(mylogit.DNAconc) lrtest(mylogit.DNAconc) X260.280 mylogit.DNAqual <- glm(POS_Both ~X260.280 , data=mydata.ALL, family=poisson(link=log)) summary(mylogit.DNAqual) lrtest(mylogit.DNAqual) ####### Difference by age of sample: mylogit.Year <- glm(POS_Both ~ Year, data=mydata.ALL, family=poisson(link=log)) summary(mylogit.Year) lrtest(mylogit.Year) ##############(3) PLOTTING RESULTS ################################# ###############SPECIES DIFFERENCES IN PREVALENCE###################### #########-----(1) FINDING PREV and 95% CI------- ################# #Find 95% CI for spp differences and adding to csv binconf(93, 1038, alpha=0.05, method="all") ?binconf MPXV_sp <- read.csv(file='MPXVPosProp_spp_CI.csv',sep=',', header=T) #read in csv file MPXV_sp blank <- matrix(NA,12,9) #create empty matrix to add to csv colnames(blank) <- c("prev_G2RG", "G2RG_lowCI", "G2RG_highCI", "prev_G2RWA", "G2RWA_lowCI", "G2RWA_highCI","prev_both", "both_lowCI", "both_highCI") MPXV_sp <- cbind(MPXV_sp,blank) citation("Hmisc") tapply(mydata.ALL$POS_Both, mydata.ALL$species.code, length) #loop for calculating prevalence levels + 95% CI for (ii in 1:length(MPXV_sp$Species)){ MPXV_sp[ii, 6:8] <- binconf(MPXV_sp[ii,2], MPXV_sp[ii,5], alpha=0.05, method="exact") #fill in for G2R_G MPXV_sp[ii, 9:11] <- binconf(MPXV_sp[ii,3], MPXV_sp[ii,5], alpha=0.05, method="exact") #fill in for G2R_G MPXV_sp[ii, 12:14] <- binconf(MPXV_sp[ii,4], MPXV_sp[ii,5], alpha=0.05, method="exact") #fill in for G2R_G } write.csv(MPXV_sp, file = 'MPXVPosProp_spp_CI.csv') #bootstrapping binomial probabilities library(boot) mydata.ALL_Fan <- subset(mydata.ALL, mydata.ALL$species.co == "F_an") head(mydata.ALL_Fan) mydata.ALL_Fba <- subset(mydata.ALL, mydata.ALL$species.co == "F_ba") mydata.ALL_Fca <- subset(mydata.ALL, mydata.ALL$species.co == "F_ca") mydata.ALL_Fco <- subset(mydata.ALL, mydata.ALL$species.co == "F_co") mydata.ALL_Fis <- subset(mydata.ALL, mydata.ALL$species.co == "F_is") mydata.ALL_Flem <- subset(mydata.ALL, mydata.ALL$species.co == "F_lem") mydata.ALL_Fleo <- subset(mydata.ALL, mydata.ALL$species.co == "F_leo") mydata.ALL_Fleu <- subset(mydata.ALL, mydata.ALL$species.co == "F_leu") mydata.ALL_Fpy <- subset(mydata.ALL, mydata.ALL$species.co == "F_py") mydata.ALL_Fsu <- subset(mydata.ALL, mydata.ALL$species.co == "F_su") mydata.ALL_Fsp <- subset(mydata.ALL, mydata.ALL$species.co == "F_sp") grep("POS_Both", colnames(mydata.ALL)) #statistic to calculate here is prevalence for G2RG amplicons grep("G2RG_F2.1p", colnames(mydata.ALL)) prevG2RG <- prevstat <- function(data, indices){ d <- data[indices, 34] #bootstrap chooses its own indices p <- sum(d)/length(d) return(p) } #statistic to calculate here is prevalence for G2RWA amplicons grep("G2R_WA.1po", colnames(mydata.ALL)) prevG2RWA <- prevstat <- function(data, indices){ d <- data[indices, 42] #bootstrap chooses its own indices p <- sum(d)/length(d) return(p) } #statistic to calculate here is prevalence for BOTH amplicons prevstat <- function(data, indices){ d <- data[indices, 44] #bootstrap chooses its own indices p <- sum(d)/length(d) return(p) } #run bootstrap, ordinary = non-parametric boot.F <- boot(mydata.ALL, statistic = prevstat, sim = "ordinary", R=1000) boot.F plot(boot.F) boot.ci(boot.F, type="norm") #########-----(1) PLOTTING SPECIES PREVALENCES + 95% CI ------- ################# #Plot main points layout(matrix(c(1,1),1, byrow = TRUE)) plot(seq(1,18,3), MPXV_sp[1:6,6], xlim = c(1,18),xaxt='n', type='p', ylab='MPXV Prevalence in Skin Specimens', xlab='', ylim=c(0,0.2)) # without x-axis points(seq(2,18,3), MPXV_sp[1:6,9]) points(seq(3,18,3), MPXV_sp[1:6,12]) axis(side=1, at=seq(1,18, by=1), labels=FALSE) #add axes lablist2.x <- c('F. anerythrus',"F. carruthersi", "F. congicus", "F. lemniscatus", "F. pyrrhopus", "All species") #labels for x-axis lablistn.x <- rep("n=", 6) #labels for "n=" lablistn.x lablistx.x <- MPXV_sp[1:6,5] #labels for sample number abline(v=seq(3.5, 18, 3)) #diving lines for plot errbar(seq(1,18,3), MPXV_sp[1:6,6], MPXV_sp[1:6,7], MPXV_sp[1:6,8], add=TRUE, col='green', errbar.col='green') #error bars for G2R_GF2 errbar(seq(2,18,3), MPXV_sp[1:6,9], MPXV_sp[1:6,10], MPXV_sp[1:6,11], add=TRUE, col='blue', errbar.col='blue') #error bars for G2R_WA errbar(seq(3,18,3), MPXV_sp[1:6,12], MPXV_sp[1:6,13], MPXV_sp[1:6,14], add=TRUE, col='red', errbar.col='red') #error bars for both amplicons legend("topright", legend = c('G2R_GF2', 'G2R_WA', 'Both amplicons'),col=c('green', 'blue', 'red'), lty = 1, ) #legend text(x = seq(3.2, 18.2, by=3), par("usr")[3] - 0.015, labels = lablist2.x, pos = 2, xpd = TRUE) #label species text(x = seq(2.2, 18.2, by=3), par("usr")[3] - 0.025, labels = lablistn.x, pos = 2, xpd = TRUE) #label "n=" text(x = seq(3, 21, by=3), par("usr")[3] - 0.025, labels = lablistx.x, pos = 2, xpd = TRUE) #lable with sample number # Use 95% confidence intervals instead of SEM library(ggplot2) MPXV_sp2boot <- read.csv(file='MPXVPosProp_spp_CI_ggplot_5sp_boot.csv',sep=',', header=T) MPXV_sp2<- read.csv(file='MPXVPosProp_spp_CI_ggplot_5sp.csv',sep=',', header=T) ### plot comparison of amplicons ggplot(MPXV_sp2, aes(x=Species, y=Prevalence, fill=amplicon)) + geom_bar(position=position_dodge(), stat="identity") + geom_errorbar(aes(ymin=lowCI, ymax=highCI), width=.2, # Width of the error bars position=position_dodge(.9)) + theme (axis.text = element_text(size=20, colour="gray22"), axis.title=element_text(size=24, face="bold"), legend.text = element_text(size=20), legend.title = element_text(size=22, face="bold" ))+ labs(x = "\nSpecies", y = "MPXV Prevalence\n") ####Plot of just either ammplicon MPXV_sp_subsetboot <-subset(MPXV_sp2boot, amplicon=="Either") MPXV_sp_subsetboot MPXV_sp_subset <- subset(MPXV_sp2, subset=amplicon=="Either") MPXV_sp_subset$Species2 <- factor(MPXV_sp_subset$Species, levels = c("F. congicus","F. anerythrus","F. lemniscatus", "F. pyrropus", "F. carruthersi", "All")) MPXV_sp_subset$Species3 <- factor(MPXV_sp_subset$Species, levels = c("F. anerythrus","F. carruthersi", "F. congicus","F. lemniscatus", "F. pyrropus", "All")) ploteither <- ggplot(MPXV_sp_subset, aes(x=Species2, y=Prevalence)) + geom_bar(position=position_dodge(), stat="identity", fill="coral2") + geom_errorbar(aes(ymin=lowCI, ymax=highCI), width=.2, # Width of the error bars position=position_dodge(.9)) + theme (axis.text = element_text(size=22, colour="gray22"), axis.title=element_text(size=30, face="bold"), axis.title.y=element_text(vjust=0.1), axis.title.x=element_text(vjust=0.1)) + labs(x = "\nSpecies", y = "MPXV Prevalence\n") + ylim(0,0.25) ploteither <- ggplot(MPXV_sp_subset, aes(x=Species3, y=Prevalence, fill=Species2)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("coral2", "coral2", "coral2", "coral2", "coral2", "cyan3")) + geom_errorbar(aes(ymin=lowCI, ymax=highCI), width=.2, size=0.8, # Width of the error bars position=position_dodge(.9)) + theme (legend.position="none", axis.text = element_text(size=22, colour="gray22"), axis.title=element_text(size=30, face="bold"), axis.title.y=element_text(vjust=0.1), axis.title.x=element_text(vjust=0.1)) + labs(x = "\nSpecies", y = "MPXV Prevalence\n") + ylim(0,0.25) ploteither citation("ggplot2") ?anova boxplot(POS_Both ~ species.co, data = mydata, col = "lightgray", main = "MPXV Prevalence Across Species", ylab = "MPVX Prevalence", ylim = c(0,0.2)) ###################### TEMPORAL DIFFERENCES: ######################### #######---------(A) Plot data across time ----------------######### mydata6 <- read.csv("Year_Pos_10samples_CI.csv", sep = ",", header = TRUE) alltime <- read.csv("Year_Pos_CI.csv", sep = ",", header = TRUE) #######get CI for each year: Loop for (ii in 1:length(mydata6$Year)){ mydata6[ii,6:8] <- binconf(mydata6[ii,5], mydata6[ii,2], alpha=0.05, method="exact") } mydata6 alltime #plot grey dots for all time points: plot(alltime[,2],alltime[,13], xaxt='n', pch=1, type='p', col= 'gray', cex = 1.5, ylab = "MPXV Prevalence", main = "MPXV Prevalence by Year \n(Both Amplicons)", xlab='',ylim=c(0,1), cex.axis = 1.5, cex.lab = 1.5) axis(side=1, at=seq(1900,1990, by=20), labels=TRUE, cex.axis = 1.5) library(Hmisc) errbar(alltime[,2],alltime[,13], alltime[,14],alltime[,15],cap=0, pch=1, cex = 1.25, col='black', add=TRUE, errbar.col = 'black') points(alltime[,2],alltime[,13], cap=0, pch=20, cex = 1.25, col='white') ?errbar #add on black >10 samples errbar(mydata6[,2],mydata6[,13], mydata6[,14],mydata6[,15],cap=0, pch=20, col='black', add=TRUE, cex = 2, errbar.col = 'black') ?legend legend(x = "topright", legend = c("<10 samples", ">= 10 samples"), pch = c(1,20), col = c("black", "black"), pt.cex = c(1.5, 2), cex = 1.5) plot(1:length(mydata6[,2]),mydata6[,6], xaxt='n', pch=20, type='p', col= 'red', ylab = "MPXV Prevalence", main = "MPXV Prevalence by Year \n(Both Amplicons)", xlab='',ylim=c(0,1)) axis(side=1, at=seq(2,length(mydata6[,2]), by=20), labels=FALSE) lablist.x <- seq(1900, 1990, 20) lablist.x text(x = seq(5, length(mydata6[,2]), by=10), par("usr")[3] - 0.05, labels = lablist.x, srt = 0, pos = 2, xpd = TRUE) errbar(1:length(mydata6[,2]), mydata6[,6], mydata6[,7], mydata6[,8], cap=0, pch=20, col='red', add=TRUE) #plot with only sample size >=10 #plot: plot(1:length(mydata6[,2]),mydata6[,6], xaxt='n', pch=20, type='p', col= 'red', ylab = "MPXV Prevalence", main = "MPXV Prevalence by Year \n(Both Amplicons)", xlim = c(12, 72), xlab='',ylim=c(0,0.7)) axis(side=1, at=seq(12,72, by=10), labels=FALSE) lablist.x <- seq(1910, 1970, 10) text(x = seq(14, 75, by=10), par("usr")[3] - 0.05, labels = lablist.x, srt = 0, pos = 2, xpd = TRUE) errbar(1:length(mydata6[,2]), mydata6[,6], mydata6[,7], mydata6[,8], cap=0, pch=20, col='red', add=TRUE) #### ANOVA: differnece between years?? #### mydata.ALL <- read.xls("all_samples_FINAL.xlsx", header=TRUE) head(mydata.ALL) #data where every sample represented anova.year <- aov(mydata.ALL$POS_Both~mydata.ALL$Year) anova.year summary(anova.year) ##see that YES there is significant differece: p=0.00415, > summary(anova.year) ##see that YES there is significant differece: p = 0.00195, # Df Sum Sq Mean Sq F value Pr(>F) # mydata.ALL$Year 1 0.68 0.6797 8.255 0.00415 ** # Residuals 963 79.30 0.0823 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # 73 observations deleted due to missingness ls(anova.sp) ###### with different species: ## ALL SPECIES: Year_All <- read.csv("Year_Pos_CI.csv", sep = ",", header = TRUE) Year_All blank <- matrix(NA, length(Year_All$Year), 9) colnames(blank) <- c("prev_G2RG", "G2RG_lowCI", "G2RG_highCI", "prev_G2RWA", "G2RWA_lowCI", "G2RWA_highCI","prev_both", "both_lowCI", "both_highCI") Year_All <- cbind(Year_All, blank) for (ii in 1:length(Year_All$Year)){ Year_All[ii,6:8] <- binconf(Year_All[ii,2], Year_All[ii,5], alpha=0.05, method="exact") Year_All[ii,9:11] <- binconf(Year_All[ii,3], Year_All[ii,5], alpha=0.05, method="exact") Year_All[ii,12:14] <- binconf(Year_All[ii,4], Year_All[ii,5], alpha=0.05, method="exact") } #Plot by year layout(matrix(c(1), 1, 1, byrow = TRUE)) op <- par(mar = c(5,6,4,2) + 0.1) ## default is c(5,4,4,2) + 0.1 plot(Year_All$Year, Year_All$prev_both, ylim = c(0,1), xlim=c(1899, 1993), ylab ="MPXV Prevalence", xlab= "Year",col='black', cex.lab=1.8, cex.axis=1.5, font.lab=2) errbar(Year_All$Year, Year_All$prev_both, Year_All$both_lowCI, Year_All$both_highCI,cap=0, pch=19, col='grey', add=TRUE) points(Year_All$Year, Year_All$prev_both, col='grey', pch=19) #emphasize in plot the points where have 10 or more samples Year_All10 <- read.csv("Year_Pos_10samples_CI.csv", sep = ",", header = TRUE) points(Year_All10$Year, Year_All10$prev_both, col='red', pch=19, type='p', lwd=2) legend("topright", legend =c("<10 samples", ">= 10 samples"), col=c('gray', 'red'), pch = 19, cex=1.5) errbar(Year_All$Year, Year_All$prev_both, Year_All$both_lowCI, Year_All$both_highCI,cap=0, pch=20, col='red', add=TRUE) ##plot sampling count Year_Fpy <- read.csv("Year_Pos_F_py_CI.csv") colnames(Year_All) plot(Year_All$Year, Year_All$Tot_Samples, type='b', pch=20, xlab='Year', ylab="Total Number of Funisciurus Samples") points(Year_Fan$Year, Year_Fan$F_ane_tot, type='b', pch=20, col="red") points(Year_Fca$Year, Year_Fca$F_car_tot, type='b', pch=20, col="blue") sum(Year_All$Tot_Samples, subset = Year_All$Year <=1960) sum(Year_All$Tot_Samples, subset = Year_All$Year >1960) sum(Year_All$Tot_Samples) sub <- subset(Year_All$Tot_Samples, subset = Year_All$Year <1960) sum(sub) 789/949 Year ###by species ######## ##importing data and creating CI and prevalence levels Year_Fpy <- read.csv("Year_Pos_F_py.csv", sep = ",", header = TRUE) Year_Fpy blank <- matrix(NA, length(Year_Fpy$Year), 9) colnames(blank) <- c("prev_G2RG", "G2RG_lowCI", "G2RG_highCI", "prev_G2RWA", "G2RWA_lowCI", "G2RWA_highCI","prev_both", "both_lowCI", "both_highCI") Year_Fpy <- cbind(Year_Fpy, blank) Year_Fpy length(Year_Fpy[1,]) for (ii in 1:length(Year_Fpy$Year)){ Year_Fpy[ii,6:8] <- binconf(Year_Fpy[ii,2], Year_Fpy[ii,5], alpha=0.05, method="exact")##for all species Year_Fpy[ii,9:11] <- binconf(Year_Fpy[ii,3], Year_Fpy[ii,5], alpha=0.05, method="exact") Year_Fpy[ii,12:14] <- binconf(Year_Fpy[ii,4], Year_Fpy[ii,5], alpha=0.05, method="exact") } write.csv(Year_All, file = 'Year_Pos_CI.csv') #Plotting different species through time: points(Year_Fan$Year, Year_Fan$prev_both, ylim =c(0,1), type='b', pch=20, col='yellow') points(Year_Fca$Year, Year_Fca$prev_both, ylim =c(0,1), type='b', pch=20, col='blue') points(Year_Fco$Year, Year_Fco$prev_both, ylim =c(0,1), type='b', pch=20, col='green') points(Year_Flem$Year, Year_Flem$prev_both, ylim =c(0,1), type='b', pch=20, col='purple') points(Year_Fpy$Year, Year_Fpy$prev_both, ylim =c(0,1), type='b', pch=20, col='orange') points(Year_All$Year, Year_All$prev_both, ylim =c(0,1), type='b', pch=20, col='red') errbar(Year_Fan$Year, Year_Fan$prev_both, Year_Fan$both_lowCI, Year_Fan$both_highCI,cap=0, pch=20, col='red', add=TRUE) #See what cut-off for number of samples need: plot(Year_All$Tot_Samples, Year_All$prev_both, pch=20, col='red') functionx3 <- lm(Year_All$prev_both ~ poly(Year_All$Tot_Samples, 3, raw=TRUE)) plot(functionx3) abline(v=10) ### with 10 samples or more: Year_All <- read.csv("Year_Pos_10samples_CI.csv", sep = ",", header = TRUE) plot(Year_All$Year, Year_All$prev_both, ylim =c(0,1), type='b', pch=20, col='red') errbar(Year_All$Year, Year_All$prev_both, Year_All$both_lowCI, Year_All$both_highCI,cap=0, pch=20, col='red', add=TRUE) Year_Fan_10 <- read.csv("Year_Pos_F_an_10samples_CI.csv", sep = ",", header = TRUE) points(Year_Fan_10$Year, Year_Fan_10$prev_both, ylim =c(0,1), type='b', pch=20, col='blue') ##############-------(B) Seasonality -----------######################## colnames(mydata.ALL) mydata.ALL$Month = factor(mydata.ALL$Month) month_logit <- glmer(POS_Both ~ Month + (1|species.code) + (1|Year_bin) + (1|Museum), data=mydata.ALL, family=binomial, na.action=na.omit) month_null <- glmer(POS_Both ~ 1 + (1|species.code) + (1|Year_bin) + (1|Museum), data=mydata.ALL, family=binomial, na.action=na.omit) car::Anova(month_logit, test.statistic="Chisq", type=c("III")) # type 3 analysis (SAS verbiage) anova(month_logit) df(x=0.8414, df1=11, df2=802) lrtest(month_logit) summary(month_logit) drop1(month_logit, test="Chisq") summary(glht(month_logit, mcp(Month="Tukey"))) MPXV_Month <- read.csv("Pos_month_analyses.csv", sep = ",", header = TRUE) MPXV_Month MPXV_Month_All <- cbind(MPXV_Month$Month, MPXV_Month$POS_BOTH, MPXV_Month$Tot_Samples) MPXV_Month_All blank<- matrix(NA, length(MPXV_Month[,1]), 3) MPXV_Month_All<- cbind(MPXV_Month_All, blank) colnames(MPXV_Month_All) <- c('Month', "POS_BOTH", "Tot_Samples", "Prevalence", "lowCI", "highCI") MPXV_Month_Fca <- cbind(MPXV_Month$Month, MPXV_Month$F_car_posALL, MPXV_Month$F_car_tot, blank) colnames(MPXV_Month_Fca) <- c('Month', "POS_BOTH", "Tot_Samples", "Prevalence", "lowCI", "highCI") for (ii in 1:12){ MPXV_Month_All[ii,4:6] <- binconf(MPXV_Month_All[ii,2], MPXV_Month_All[ii,3], alpha=0.05, method="exact")##for all species } MPXV_Month_Fca binconf(11,600, alpha=0.05, method="exact") write.csv(MPXV_Month_Fca, file = 'Month_Fca_CI.csv') #Plot all vs. other species op <- par(mar = c(5,5,4,2) + 0.1) ## default is c(5,4,4,2) + 0.1 plot(MPXV_Month_All[,1], MPXV_Month_All[,4], xaxt='n', ylim =c(0,0.4), lwd=2,type='b', pch=20, cex=2, col='red', xlab="Month", ylab= "MPXV Prevalence", cex.lab=1.8, cex.axis=1.5, font.lab=2) axis(side=1, at=seq(1,12, by=1), labels=FALSE) lablist.x <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep","Oct", "Nov", "Dec") text(x = seq(1.4, 12.4, 1), par("usr")[3] - 0.03, labels = lablist.x, srt = 0, pos = 2, xpd = TRUE, cex=1.5) errbar(MPXV_Month_All[,1], MPXV_Month_All[,4], MPXV_Month_All[,5], MPXV_Month_All[,6], cap=0, pch=20, col='red', add=TRUE) points(MPXV_Month_All[,1], MPXV_Month_All[,4], xaxt='n', ylim =c(0,0.4), lwd=2,type='b', pch=20, cex=2, col='red', xlab="Month", ylab= "MPXV Prevalence", cex.lab=1.8, cex.axis=1.5, font.lab=2) points(MPXV_Month_Fan[,1], MPXV_Month_Fan[,4], type='b', pch=20, col='blue') points(MPXV_Month_Fca[,1], MPXV_Month_Fca[,4], type='b', pch=20, col='purple') points(MPXV_Month_Fco[,1], MPXV_Month_Fco[,4], type='b', pch=20, col='green') points(MPXV_Month_Fpy[,1], MPXV_Month_Fpy[,4], type='b', pch=20, col='orange') legend("topright", legend = c('All Funisciurus', 'F. anerythrus', "F. carruthersi", 'F. congicus', "F. pyrrhopus"),col=c('red', 'blue', "purple", 'green', 'orange'), lty = 1, ) #legend #Plot species layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE)) plot(MPXV_Month_Fan[,1], MPXV_Month_Fan[,4], xaxt='n', ylim =c(0,0.6), type='b', pch=20, col='blue', xlab="Month", ylab= "MPXV Prevalence", main='F. anerythrus') axis(side=1, at=seq(1,12, by=1), labels=FALSE) lablist.x <- c("J", "F", "M", "A", "M", "J", "J", "A", "S","O", "N", "D") text(x = seq(1.6, 12.6, 1), par("usr")[3] - 0.06, labels = lablist.x, srt = 0, pos = 2, xpd = TRUE) errbar(MPXV_Month_Fan[,1], MPXV_Month_Fan[,4], MPXV_Month_Fan[,5], MPXV_Month_Fan[,6], cap=0, pch=20, col='blue', add=TRUE) plot(MPXV_Month_Fco[,1], MPXV_Month_Fco[,4], xaxt='n', ylim =c(0,0.6), type='b', pch=20, col='green', xlab="Month", ylab= "MPXV Prevalence", main='F. congicus') axis(side=1, at=seq(1,12, by=1), labels=FALSE) lablist.x <- c("J", "F", "M", "A", "M", "J", "J", "A", "S","O", "N", "D") text(x = seq(1.6, 12.6, 1), par("usr")[3] - 0.06, labels = lablist.x, srt = 0, pos = 2, xpd = TRUE) errbar(MPXV_Month_Fco[,1], MPXV_Month_Fco[,4], MPXV_Month_Fco[,5], MPXV_Month_Fco[,6], cap=0, pch=20, col='green', add=TRUE)