# ESCI Field Camp # Frog survey data, Chuckanut Community Forest (CCF) # Wed evening 3 April 2024 ______________________________________________________________________________ R commands only, w/out prompts or output # DATA: our field survey 4/3/2024 # Wetland Labels # AA, AX, AY, CC, DD, EE, HH, JJ, KK, GG area.sf <- c(8898, 130, 498, 109538, 5919, 919, 8764, 1000000, 72181, 20) stems <- c(15, 0, 0, 50, 10, 5, 25, 100, 70, 0) layers <- c(3, 2, 2, 4, 3, 2, 4, 4, 4, 1) area.m <- 0.0929 * area.sf # (in square meters) area.m frog.ccf <- c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0) # Binary: frogs=1, no frogs=0 frog.ccf # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Fit logistic regression model: frogs ~ Logit(area) frog.mod <- glm(frog.ccf ~ area.m, family=binomial) summary(frog.mod) ################################################# # Sample size too small to fit logistic regression model. # Lesson for your research projects: # imperative to plan & collect large enough samples # For illustration of effective analysis, artificially increase dataset # by "adding" seven survey sites to the sample. # Wetland Labels # AA, AX, AY, CC, DD, EE, HH, JJ, KK, GG, LL, MM, nn, oo, pp, qq, rr # MM=southwest of JJ; nn=@South Ave; oo=E Interuban trail; # pp, qq, rr are fictional wetlands invented to demonstrate logistic modeling # Add 7 values to each variable area.m2 <- c(area.m, 151.52, 223.15, 1858.0, 3716.0, 26000.0, 50000.0, 20000.0) area.m2 stems2 <- c(stems, 2, 15, 12, 40, 5, 40, 20) stems2 layers2 <- c(layers, 1, 3, 3, 3, 4, 3, 3) layers2 frog.ccf2 <- c(frog.ccf, 0, 0, 0, 0, 0, 1, 1) frog.ccf2 # Artificially increase area of wetlands CC and KK area.m2[4] <- 28756.08 area.m2[9] <- 15995.61 area.m2 # Also convert wetlands CC and KK from no frogs to frogs detected frog.ccf2[4] <- 1 frog.ccf2[9] <- 1 frog.ccf2 ###################################################### # Plot data and model (frogs ~ area) plot(area.m2, jitter(frog.ccf2, 0.1), cex=1.5, xlab="Wetland area (m2)", ylab="Probability(frog detection)") # Fit logistic regression model: frogs ~ Logit(area) frog.mod2 <- glm(frog.ccf2 ~ area.m2, family=binomial) summary(frog.mod2) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Add logistic regression model to data plot (frogs ~ area) area <- seq(0, 95000, by=100) # create dummy variable for smooth line f.pred <- exp(-3.639 + 1.980e-4*area) / (1 + exp(-3.639 + 1.980e-4*area)) lines(area, f.pred) # plot model +/- standard error, as dotted lines f.pred.plus <- exp(-3.639+(1.980e-4 + 9.562e-05)*area) / (1+exp(-3.639 + (1.980e-4 + 9.562e-05)*area)) f.pred.minus <- exp(-3.639+(1.980e-4 - 9.562e-05)*area) / (1+exp(-3.639 + (1.980e-4 - 9.562e-05)*area)) lines(area, f.pred.plus, lty=2) lines(area, f.pred.minus, lty=2) # Save figure as JPEG: jpeg(file="frog.area.ccf.jpg") plot(area.m2, jitter(frog.ccf2, 0.1), cex=1.5, xlab="Wetland area (m2)", ylab="Probability(frog detection)") lines(area, f.pred) lines(area, f.pred.plus, lty=2) lines(area, f.pred.minus, lty=2) dev.off() ######################################################### # Plot data and model (frogs ~ stem density) plot(stems2, jitter(frog.ccf2, 0.1), cex=1.5, xlab="Stem density (#/m2)", ylab="Probability(frog detection)") # Fit logistic regression model: frogs ~ Logit(area) frog.mod2.stem <- glm(frog.ccf2 ~ stems2, family=binomial) summary(frog.mod2.stem) # Add logistic regression model to data plot (frogs ~ stem density) stem <- seq(0, 100, by=0.1) # create dummy variable for smooth line f.pred.stem <- exp(-4.217 + 0.1235*stem) / (1 + exp(-4.217 + 0.1235*stem)) lines(stem, f.pred.stem) # plot model +/- standard error, as dotted lines f.pred.stem.plus <- exp(-4.217 +(0.1235+0.06008)*stem) / (1+exp(-4.217+(0.1235 + 0.06008)*stem)) f.pred.stem.minus <- exp(-4.217 +(0.1235 - 0.06008)*stem) / (1+exp(-4.217+(0.1235 - 0.06008)*stem)) lines(stem, f.pred.stem.plus, lty=2) lines(stem, f.pred.stem.minus, lty=2) ######################################################################## # Plot data and model (frogs ~ veg layers) plot(layers2, jitter(frog.ccf2, 0.1), cex=1.5, xlab="No. vegetation layers", ylab="Probability(frog detection)") # Fit logistic regression model: frogs ~ Logit(veg. layers) frog.mod2.layer <- glm(frog.ccf2 ~ layers2, family=binomial) summary(frog.mod2.layer) # Add logistic regression model to data plot (frogs ~ veg. layers) layer <- seq(0, 4, by=0.01) # create dummy variable for smooth line f.pred.layer <- exp(-6.429 + 1.7487*layer) / (1 + exp(-6.429 + 1.7487*layer)) lines(layer, f.pred.layer) # plot model +/- standard error, as dotted lines f.pred.layer.plus <- exp(-6.429 +(1.7487+0.9984)*layer) / (1+exp(-6.429+(1.7487 + 0.9984)*layer)) f.pred.layer.minus <- exp(-6.429 +(1.7487 - 0.9984)*layer) / (1+exp(-6.429+(1.7487 - 0.9984)*layer)) lines(layer, f.pred.layer.plus, lty=2) lines(layer, f.pred.layer.minus, lty=2) ############################################################################## ############################################################################## # Full R transcript, including output R version 4.3.3 (2024-02-29 ucrt) -- "Angel Food Cake" Copyright (C) 2024 The R Foundation for Statistical Computing > # ESCI Field Camp > # Frog survey data, Chuckanut Community Forest (CCF) > # Wed evening 3 April 2024 > > # DATA: our field survey 4/3/2024 > # Wetland Labels > # AA, AX, AY, CC, DD, EE, HH, JJ, KK, GG > area.sf <- c(8898, 130, 498, 109538, 5919, 919, 8764, 1000000, 72181, 20) > stems <- c(15, 0, 0, 50, 10, 5, 25, 100, 70, 0) > layers <- c(3, 2, 2, 4, 3, 2, 4, 4, 4, 1) > area.m <- 0.0929 * area.sf # (in square meters) > area.m [1] 826.6242 12.0770 46.2642 10176.0802 549.8751 85.3751 [7] 814.1756 92900.0000 6705.6149 1.8580 > frog.ccf <- c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0) # Binary: frogs=1, no frogs=0 > frog.ccf [1] 0 0 0 0 0 0 0 1 0 0 > # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > # Fit logistic regression model: frogs ~ Logit(area) > frog.mod <- glm(frog.ccf ~ area.m, family=binomial) > summary(frog.mod) Call: glm(formula = frog.ccf ~ area.m, family = binomial) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -2.805e+01 4.586e+04 -0.001 1 area.m 5.597e-04 1.250e+00 0.000 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 6.5017e+00 on 9 degrees of freedom Residual deviance: 5.3893e-10 on 8 degrees of freedom AIC: 4 Number of Fisher Scoring iterations: 23 > ################################################# > # Sample size too small to fit logistic regression model. > # Lesson for your research projects: > # imperative to plan & collect large enough samples > > # For illustration of effective analysis, artificially increase dataset > # by "adding" seven survey sites to the sample. > > # Wetland Labels > # AA, AX, AY, CC, DD, EE, HH, JJ, KK, GG, LL, MM, nn, oo, pp, qq, rr > # MM=southwest of JJ; nn=@South Ave; oo=E Interuban trail; > # pp, qq, rr are fictional wetlands invented to demonstrate logistic modeling > # Add 7 values to each variable > area.m2 <- c(area.m, 151.52, 223.15, 1858.0, 3716.0, 26000.0, 50000.0, 20000.0) > area.m2 [1] 826.6242 12.0770 46.2642 10176.0802 549.8751 85.3751 [7] 814.1756 92900.0000 6705.6149 1.8580 151.5200 223.1500 [13] 1858.0000 3716.0000 26000.0000 50000.0000 20000.0000 > stems2 <- c(stems, 2, 15, 12, 40, 5, 40, 20) > stems2 [1] 15 0 0 50 10 5 25 100 70 0 2 15 12 40 5 40 20 > layers2 <- c(layers, 1, 3, 3, 3, 4, 3, 3) > layers2 [1] 3 2 2 4 3 2 4 4 4 1 1 3 3 3 4 3 3 > frog.ccf2 <- c(frog.ccf, 0, 0, 0, 0, 0, 1, 1) > frog.ccf2 [1] 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 > # Artificially increase area of wetlands CC and KK > area.m2[4] <- 28756.08 > area.m2[9] <- 15995.61 > area.m2 [1] 826.6242 12.0770 46.2642 28756.0800 549.8751 85.3751 [7] 814.1756 92900.0000 15995.6100 1.8580 151.5200 223.1500 [13] 1858.0000 3716.0000 26000.0000 50000.0000 20000.0000 > # Also convert wetlands CC and KK from no frogs to frogs detected > frog.ccf2[4] <- 1 > frog.ccf2[9] <- 1 > frog.ccf2 [1] 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 1 > ###################################################### > # Plot data and model (frogs ~ area) > plot(area.m2, jitter(frog.ccf2, 0.1), cex=1.5, xlab="Wetland area (m2)", + ylab="Probability(frog detection)") > # Fit logistic regression model: frogs ~ Logit(area) > frog.mod2 <- glm(frog.ccf2 ~ area.m2, family=binomial) > summary(frog.mod2) Call: glm(formula = frog.ccf2 ~ area.m2, family = binomial) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -3.639e+00 1.736e+00 -2.096 0.0360 * area.m2 1.980e-04 9.562e-05 2.070 0.0384 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 20.5971 on 16 degrees of freedom Residual deviance: 7.3442 on 15 degrees of freedom AIC: 11.344 Number of Fisher Scoring iterations: 7 > # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > # Add logistic regression model to data plot (frogs ~ area) > area <- seq(0, 95000, by=100) # create dummy variable for smooth line > f.pred <- exp(-3.639 + 1.980e-4*area) / (1 + exp(-3.639 + 1.980e-4*area)) > lines(area, f.pred) > # plot model +/- standard error, as dotted lines > f.pred.plus <- + exp(-3.639+(1.980e-4 + 9.562e-05)*area) / (1+exp(-3.639 + (1.980e-4 + 9.562e-05)*area)) > f.pred.minus <- + exp(-3.639+(1.980e-4 - 9.562e-05)*area) / (1+exp(-3.639 + (1.980e-4 - 9.562e-05)*area)) > lines(area, f.pred.plus, lty=2) > lines(area, f.pred.minus, lty=2) > # Save figure as JPEG: > jpeg(file="frog.area.ccf.jpg") > plot(area.m2, jitter(frog.ccf2, 0.1), cex=1.5, xlab="Wetland area (m2)", + ylab="Probability(frog detection)") > lines(area, f.pred) > lines(area, f.pred.plus, lty=2) > lines(area, f.pred.minus, lty=2) > dev.off() > ######################################################### > # Plot data and model (frogs ~ stem density) > plot(stems2, jitter(frog.ccf2, 0.1), cex=1.5, xlab="Stem density (#/m2)", + ylab="Probability(frog detection)") > # Fit logistic regression model: frogs ~ Logit(area) > frog.mod2.stem <- glm(frog.ccf2 ~ stems2, family=binomial) > summary(frog.mod2.stem) Call: glm(formula = frog.ccf2 ~ stems2, family = binomial) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -4.21713 1.90433 -2.214 0.0268 * stems2 0.12351 0.06008 2.056 0.0398 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 20.5971 on 16 degrees of freedom Residual deviance: 8.5094 on 15 degrees of freedom AIC: 12.509 Number of Fisher Scoring iterations: 6 > # Add logistic regression model to data plot (frogs ~ stem density) > stem <- seq(0, 100, by=0.1) # create dummy variable for smooth line > f.pred.stem <- exp(-4.217 + 0.1235*stem) / (1 + exp(-4.217 + 0.1235*stem)) > lines(stem, f.pred.stem) > # plot model +/- standard error, as dotted lines > f.pred.stem.plus <- + exp(-4.217 +(0.1235+0.06008)*stem) / (1+exp(-4.217+(0.1235 + 0.06008)*stem)) > f.pred.stem.minus <- + exp(-4.217 +(0.1235 - 0.06008)*stem) / (1+exp(-4.217+(0.1235 - 0.06008)*stem)) > lines(stem, f.pred.stem.plus, lty=2) > lines(stem, f.pred.stem.minus, lty=2) > ######################################################################## > # Plot data and model (frogs ~ veg layers) > plot(layers2, jitter(frog.ccf2, 0.1), cex=1.5, xlab="No. vegetation layers", + ylab="Probability(frog detection)") > # Fit logistic regression model: frogs ~ Logit(veg. layers) > frog.mod2.layer <- glm(frog.ccf2 ~ layers2, family=binomial) > summary(frog.mod2.layer) Call: glm(formula = frog.ccf2 ~ layers2, family = binomial) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -6.4293 3.4305 -1.874 0.0609 . layers2 1.7487 0.9984 1.751 0.0799 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 20.597 on 16 degrees of freedom Residual deviance: 15.583 on 15 degrees of freedom AIC: 19.583 Number of Fisher Scoring iterations: 5 > # Add logistic regression model to data plot (frogs ~ veg. layers) > layer <- seq(0, 4, by=0.01) # create dummy variable for smooth line > f.pred.layer <- exp(-6.429 + 1.7487*layer) / (1 + exp(-6.429 + 1.7487*layer)) > lines(layer, f.pred.layer) > # plot model +/- standard error, as dotted lines > f.pred.layer.plus <- + exp(-6.429 +(1.7487+0.9984)*layer) / (1+exp(-6.429+(1.7487 + 0.9984)*layer)) > f.pred.layer.minus <- + exp(-6.429 +(1.7487 - 0.9984)*layer) / (1+exp(-6.429+(1.7487 - 0.9984)*layer)) > lines(layer, f.pred.layer.plus, lty=2) > lines(layer, f.pred.layer.minus, lty=2)