Warning: package 'lattice' was built under R version 4.3.3
This is vegan 2.6-4
library(gridExtra)
Attaching package: 'gridExtra'
The following object is masked from 'package:dplyr':
combine
Data Cleaning
#load in the visual survey dataarth <-read.csv("Raw Data/visual_surveys.csv")arth$plant.id <-as.character(arth$plant.id)#load plant measurementsplt <-read.csv("Raw Data/plant_data.csv")#filter out the silver chollasc <-filter(plt, Species =="silvercholla") #18trap is a plant with a pitfall trap that was never surveyssc <- sc %>%filter(PlantID !="18trap")#join the survey data to the plant measurementsdata <-left_join(sc, arth, by =c("PlantID"="plant.id", "year")) data <-select(data, 1:13, 31:103)#remove the half survey for simplicitydata <- data %>%filter(days.since.treatment !=13)str(data)
'data.frame': 1180 obs. of 86 variables:
$ PlantID : chr "1" "1" "1" "1" ...
$ Species : chr "silvercholla" "silvercholla" "silvercholla" "silvercholla" ...
$ date.x : num 4.25 4.25 4.25 4.25 4.25 4.25 4.25 4.25 4.25 4.25 ...
$ year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
$ x : int 58 58 58 58 58 58 58 58 58 39 ...
$ y : int 36 36 36 36 36 36 36 36 36 28 ...
$ z : int 65 65 65 65 65 65 65 65 65 54 ...
$ treatment : chr "C" "C" "C" "C" ...
$ growth.nodes : int 110 110 110 110 110 110 110 110 110 97 ...
$ new.segments : int 41 41 41 41 41 41 41 41 41 27 ...
$ buds : int 49 49 49 49 49 49 49 49 49 55 ...
$ aborted.buds : int NA NA NA NA NA NA NA NA NA NA ...
$ open.flowers : int NA NA NA NA NA NA NA NA NA NA ...
$ date.y : chr "4.9.2023" "4.10.2023" "4.12.2023" "4.15.2023" ...
$ time.of.day : chr "morning" "morning" "morning" "afternoon" ...
$ days.since.treatment : int 0 1 3 6 9 12 17 22 24 0 ...
$ CB.eggs : int NA NA NA NA NA NA NA NA 3 NA ...
$ adult.Chelinidea.vittiger : int 3 2 NA 2 2 NA 1 NA NA NA ...
$ nymph.Chelinidea.vittiger : int NA NA NA NA NA NA NA NA NA NA ...
$ Notogramma.purpuratum : int NA NA NA NA NA NA NA NA NA 1 ...
$ Narnia : int NA NA NA NA NA NA NA NA NA NA ...
$ Crematogaster.depilis : int 1 NA NA 5 2 1 1 15 10 3 ...
$ Crematogaster.depilis.tube: int NA NA NA NA NA NA NA NA NA NA ...
$ Endiodioctes : int NA NA NA NA NA NA NA NA NA NA ...
$ Endiodioctes.tube : int NA NA NA NA NA NA NA NA NA NA ...
$ Eremocystus : int NA NA NA NA NA NA NA NA NA NA ...
$ Monomorium.ergatogyna : int NA NA NA NA NA NA NA NA NA NA ...
$ Camponotus.sayi : int NA NA NA NA NA NA NA NA NA NA ...
$ Solenopsis.xyloni : int NA NA NA NA NA NA NA NA NA NA ...
$ Forelius.pruinosis : int NA NA NA NA NA NA NA NA NA NA ...
$ Myrmecosystus.yellow : int NA NA NA NA NA NA NA NA NA NA ...
$ geocoris : int NA NA NA NA NA NA NA NA NA NA ...
$ orange.geocorid : int NA NA NA 1 NA NA NA NA NA NA ...
$ arrhysus : int NA NA NA NA NA NA NA NA NA NA ...
$ Largus.californicus : int NA NA NA NA NA NA NA NA NA NA ...
$ imm.cal : int NA NA NA NA NA NA NA NA NA NA ...
$ Leptoglossus.clypealus : int NA NA NA NA NA NA NA NA NA NA ...
$ black.parasitoid.wasp : int NA NA NA NA NA NA NA NA NA NA ...
$ green.stink.bug : int NA NA NA NA NA NA NA NA NA NA ...
$ stink.nymph : int NA NA NA NA NA NA NA NA NA NA ...
$ small.hemip : int NA NA NA NA NA NA NA NA NA NA ...
$ wingless.wasp : int NA NA NA NA NA NA NA NA NA NA ...
$ long.parasitoid.wasp : int NA NA NA NA NA NA NA NA NA NA ...
$ aphid.outbreak : int NA NA NA NA NA NA NA NA NA NA ...
$ notes : chr "" "" "" "" ...
$ tiny.wasp : int NA NA NA NA NA NA NA NA NA NA ...
$ salticidae : int NA NA NA NA NA NA NA NA NA NA ...
$ aphid : int NA NA NA NA NA NA NA NA NA NA ...
$ braconid : int NA NA NA NA NA NA NA NA NA NA ...
$ lacewing : int NA NA NA NA NA NA NA NA NA NA ...
$ shiny.black.fly : int NA NA NA 1 NA NA NA NA NA NA ...
$ trupanea. : int NA NA NA NA NA NA NA NA NA NA ...
$ red.and.black.hemipteran : int NA NA NA NA NA NA NA NA NA NA ...
$ other.hemip : int NA NA NA NA NA NA NA NA NA NA ...
$ eremochrysa : int NA NA NA NA NA NA NA NA NA NA ...
$ ladybug : int NA NA NA NA NA NA NA NA NA NA ...
$ pompilidae : int NA NA NA NA NA NA NA NA NA NA ...
$ syrphid : int NA NA NA NA NA NA NA NA NA NA ...
$ chrysomelidae : int NA NA NA NA NA NA NA NA NA NA ...
$ orb.spider : int NA NA NA NA NA NA NA NA NA NA ...
$ antracine.bombyliidae : int NA NA NA NA NA NA NA NA NA NA ...
$ caterpillar : int NA NA NA NA NA NA NA NA NA NA ...
$ lynx.spider : int NA NA NA NA NA NA NA NA NA NA ...
$ green.crab.spider : int NA NA NA NA NA NA NA NA NA NA ...
$ ichneumoidae : int NA NA NA NA NA NA NA NA NA NA ...
$ fungus.gnat : int NA NA NA NA NA NA NA NA NA NA ...
$ anthomyiidae : int NA NA NA NA NA NA NA NA NA NA ...
$ sptted.wing.fly : int NA NA NA NA NA NA NA NA NA NA ...
$ black.geocoris : int NA NA NA NA NA NA NA NA NA NA ...
$ lasioglossum : int NA NA NA NA NA NA NA NA NA NA ...
$ sml.black.coccinelid : int NA NA NA NA NA NA NA NA NA NA ...
$ X : logi NA NA NA NA NA NA ...
$ cranefly : int NA NA NA NA NA NA NA NA NA NA ...
$ other.spider : int NA NA NA NA NA NA NA NA NA NA ...
$ tetracanthus.assasin.bug : chr "" "" "" "" ...
$ redblackmoth : int NA NA NA NA NA NA NA NA NA NA ...
$ redblackimmaturehemip : chr "" "" "" "" ...
$ black.specid : int NA NA NA NA NA NA NA NA NA NA ...
$ sarcophagidae : int NA NA NA NA NA NA NA NA NA NA ...
$ green.lygus : int NA NA NA NA NA NA NA NA NA NA ...
$ chrysididae : int NA NA NA NA NA NA NA NA NA NA ...
$ Berytidae : int NA NA NA NA NA NA NA NA NA NA ...
$ philodromidae : int NA NA NA NA NA NA NA NA NA NA ...
$ Trichodes : int NA NA NA NA NA NA NA NA NA NA ...
$ brown.hemip : chr "" "" "" "" ...
$ assasin.bug..apiomeris. : chr "" "" "" "" ...
# pres * treatment interaction is non-significant# days since treatment * treatment IS significant, adding year interaction doesn't impact itggplot(data, aes(days.since.treatment, herbs.all, fill = treatment)) +geom_smooth(method ="lm") +facet_grid(~year)
`geom_smooth()` using formula = 'y ~ x'
test(emtrends(m1int, pairwise~treatment, var ="days.since.treatment", type ="response"))
$emtrends
treatment days.since.treatment.trend SE df z.ratio p.value
C 0.0161 0.00903 Inf 1.788 0.0738
N -0.0115 0.00948 Inf -1.209 0.2268
Results are averaged over the levels of: pres
$contrasts
contrast estimate SE df z.ratio p.value
C - N 0.0276 0.013 Inf 2.122 0.0339
Results are averaged over the levels of: pres
emmip(m1int, days.since.treatment ~ treatment, data = data)
# using ant abundance instead of presencem1abunint <-glmmTMB(herbs.all ~ ants + treatment * days.since.treatment+ new.segments + preds + (1|year) + (1|uniID), family ="poisson", data = data)check_overdispersion(m1abunint)
# Overdispersion test
dispersion ratio = 1.021
Pearson's Chi-Squared = 869.165
p-value = 0.325
test(emtrends(m1int_pres, pairwise ~ treatment, var ="days.since.treatment"))
$emtrends
treatment days.since.treatment.trend SE df z.ratio p.value
C 0.0223 0.0102 Inf 2.187 0.0287
N -0.0125 0.0110 Inf -1.135 0.2565
Results are averaged over the levels of: pres
$contrasts
contrast estimate SE df z.ratio p.value
C - N 0.0348 0.0149 Inf 2.334 0.0196
Results are averaged over the levels of: pres
ggplot(nozer, aes(new.segments, fill = treatment, alpha =0.5)) +geom_density(position ="dodge") +facet_grid(~ant.species)
Warning: Width not defined
ℹ Set with `position_dodge(width = ...)`
ggplot(nozer, aes(x, fill = treatment, alpha =0.5)) +geom_density(position ="dodge") +facet_grid(~ant.species)
Warning: Width not defined
ℹ Set with `position_dodge(width = ...)`
#differences between species on control plantscozer <-filter(nozer, treatment =="C")ggplot(nozer, aes(ant.species, new.segments)) +geom_boxplot() +facet_grid(~treatment)
#ggplot(nozer, aes(ant.species, x)) + geom_boxplot() + facet_grid(~treatment)#agregrate data at the plant levelsc$uniID <-paste(sc$PlantID, sc$year)vis <- antslong %>%group_by(uniID, ant.species) %>%summarise(abun =sum(abun))
`summarise()` has grouped output by 'uniID'. You can override using the
`.groups` argument.
vis <-left_join(vis, sc, by ="uniID")vis <-mutate(vis, pres =ifelse(abun >0, 1, 0))visno <-filter(vis, pres >0)nozer <-filter(visno, ant.species =="Solenopsis.xyloni"| ant.species =="Crematogaster.depilis"| ant.species =="Endiodioctes")cozer <-filter(nozer, treatment =="C")m1 <-glmmTMB(new.segments ~ ant.species + (1|year), family ="nbinom1", data = cozer)#m2 <- glmmTMB(new.segments ~ ant.species + (1|year), family = "nbinom2", data = cozer)#AIC(m1, m2)#using nbinom1summary(m1)
Family: nbinom1 ( log )
Formula: new.segments ~ ant.species + (1 | year)
Data: cozer
AIC BIC logLik deviance df.resid
363.7 372.3 -176.9 353.7 36
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
year (Intercept) 0.02284 0.1511
Number of obs: 41, groups: year, 2
Dispersion parameter for nbinom1 family (): 7.29
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.7565 0.1337 28.087 <2e-16 ***
ant.speciesEndiodioctes -0.6357 0.2928 -2.172 0.0299 *
ant.speciesSolenopsis.xyloni 0.3737 0.1588 2.353 0.0186 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
NOTE: Results may be misleading due to involvement in interactions
$emmeans
ant.species emmean SE df asymp.LCL asymp.UCL
Crematogaster.depilis 3.80 0.101 Inf 3.60 4.00
Endiodioctes 3.55 0.177 Inf 3.20 3.90
Solenopsis.xyloni 3.99 0.121 Inf 3.75 4.23
Results are averaged over the levels of: treatment
Results are given on the log (not the response) scale.
Confidence level used: 0.95
$contrasts
contrast estimate SE df z.ratio p.value
Crematogaster.depilis - Endiodioctes 0.252 0.170 Inf 1.484 0.2988
Crematogaster.depilis - Solenopsis.xyloni -0.189 0.111 Inf -1.702 0.2045
Endiodioctes - Solenopsis.xyloni -0.440 0.186 Inf -2.373 0.0464
Results are averaged over the levels of: treatment
Results are given on the log (not the response) scale.
P value adjustment: tukey method for comparing a family of 3 estimates
emmeans(m2, pairwise~treatment|ant.species)
$emmeans
ant.species = Crematogaster.depilis:
treatment emmean SE df asymp.LCL asymp.UCL
C 3.77 0.116 Inf 3.54 4.00
N 3.83 0.121 Inf 3.59 4.07
ant.species = Endiodioctes:
treatment emmean SE df asymp.LCL asymp.UCL
C 3.19 0.302 Inf 2.60 3.78
N 3.91 0.143 Inf 3.63 4.19
ant.species = Solenopsis.xyloni:
treatment emmean SE df asymp.LCL asymp.UCL
C 4.14 0.170 Inf 3.80 4.47
N 3.84 0.129 Inf 3.59 4.10
Results are given on the log (not the response) scale.
Confidence level used: 0.95
$contrasts
ant.species = Crematogaster.depilis:
contrast estimate SE df z.ratio p.value
C - N -0.0556 0.126 Inf -0.443 0.6581
ant.species = Endiodioctes:
contrast estimate SE df z.ratio p.value
C - N -0.7235 0.312 Inf -2.317 0.0205
ant.species = Solenopsis.xyloni:
contrast estimate SE df z.ratio p.value
C - N 0.2928 0.181 Inf 1.622 0.1048
Results are given on the log (not the response) scale.
emmeans(m2, pairwise~ant.species|treatment)
$emmeans
treatment = C:
ant.species emmean SE df asymp.LCL asymp.UCL
Crematogaster.depilis 3.77 0.116 Inf 3.54 4.00
Endiodioctes 3.19 0.302 Inf 2.60 3.78
Solenopsis.xyloni 4.14 0.170 Inf 3.80 4.47
treatment = N:
ant.species emmean SE df asymp.LCL asymp.UCL
Crematogaster.depilis 3.83 0.121 Inf 3.59 4.07
Endiodioctes 3.91 0.143 Inf 3.63 4.19
Solenopsis.xyloni 3.84 0.129 Inf 3.59 4.10
Results are given on the log (not the response) scale.
Confidence level used: 0.95
$contrasts
treatment = C:
contrast estimate SE df z.ratio p.value
Crematogaster.depilis - Endiodioctes 0.5857 0.304 Inf 1.926 0.1314
Crematogaster.depilis - Solenopsis.xyloni -0.3628 0.172 Inf -2.108 0.0881
Endiodioctes - Solenopsis.xyloni -0.9485 0.331 Inf -2.868 0.0115
treatment = N:
contrast estimate SE df z.ratio p.value
Crematogaster.depilis - Endiodioctes -0.0822 0.150 Inf -0.547 0.8478
Crematogaster.depilis - Solenopsis.xyloni -0.0143 0.138 Inf -0.104 0.9941
Endiodioctes - Solenopsis.xyloni 0.0679 0.158 Inf 0.430 0.9031
Results are given on the log (not the response) scale.
P value adjustment: tukey method for comparing a family of 3 estimates
Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
3.5.0.
ℹ Please use the `legend.position.inside` argument of `theme()` instead.
a
Warning: Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
ag$uniID <-paste(ag$PlantID, ag$year)sc$uniID <-paste(sc$PlantID, sc$year)ag$year <-as.integer(ag$year)ag <-left_join(ag, sc, by ="uniID")str(ag)
tibble [140 × 44] (S3: tbl_df/tbl/data.frame)
$ PlantID.x : chr [1:140] "1" "1" "10" "10" ...
$ year.x : int [1:140] 1 2 1 2 1 2 1 2 1 2 ...
$ Crematogaster.depilis: num [1:140] 29 15 0 0 47 0 0 0 13 2 ...
$ Endiodioctes : num [1:140] 0 0 0 0 0 0 0 0 0 0 ...
$ Eremocystus : num [1:140] 0 0 0 0 0 0 0 0 0 3 ...
$ Monomorium.ergatogyna: num [1:140] 0 0 0 0 0 0 0 0 0 0 ...
$ Camponotus.sayi : num [1:140] 0 0 0 0 0 0 0 0 0 0 ...
$ Solenopsis.xyloni : num [1:140] 0 3 0 0 0 0 0 0 0 0 ...
$ Forelius.pruinosis : num [1:140] 0 0 0 0 0 0 0 0 0 0 ...
$ Myrmecosystus.yellow : num [1:140] 0 0 0 0 0 0 0 0 0 0 ...
$ richness : int [1:140] 1 2 0 0 1 0 0 0 1 2 ...
$ uniID : chr [1:140] "1 2023" "1 2024" "10 2023" "10 2024" ...
$ PlantID.y : chr [1:140] "1" "1" "10" "10" ...
$ Species : chr [1:140] "silvercholla" "silvercholla" "silvercholla" "silvercholla" ...
$ date : num [1:140] 4.25 NA 4.25 NA 4.25 NA 4.25 NA 4.25 NA ...
$ year.y : int [1:140] 2023 2024 2023 2024 2023 2024 2023 2024 2023 2024 ...
$ x : int [1:140] 58 58 65 50 48 43 55 76 40 52 ...
$ y : int [1:140] 36 35 38 31 40 33 50 70 38 29 ...
$ z : int [1:140] 65 70 41 43 44 36 67 62 52 64 ...
$ treatment : chr [1:140] "C" "C" "N" "N" ...
$ growth.nodes : int [1:140] 110 NA 96 NA 98 NA 92 NA 166 NA ...
$ new.segments : int [1:140] 41 50 25 31 49 31 22 83 72 17 ...
$ buds : int [1:140] 49 101 30 81 11 58 40 93 41 36 ...
$ aborted.buds : int [1:140] NA NA NA NA NA NA 1 NA 2 NA ...
$ open.flowers : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ LT : int [1:140] 2 NA 1 NA NA NA NA NA 2 NA ...
$ AS : int [1:140] 1 NA NA NA NA NA 3 NA 2 NA ...
$ dead : int [1:140] 2 NA 4 NA 5 NA 6 NA NA NA ...
$ CR : int [1:140] NA NA 1 NA 1 NA NA NA NA NA ...
$ EC : int [1:140] 1 NA NA NA 1 NA NA NA 2 NA ...
$ YS : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ ecoop : int [1:140] 1 NA NA NA NA NA NA NA NA NA ...
$ TM : int [1:140] 1 NA NA NA NA NA NA NA NA NA ...
$ K : int [1:140] 1 NA NA NA NA NA NA NA NA NA ...
$ BB : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ CE : int [1:140] NA NA NA NA NA NA 1 NA NA NA ...
$ CA : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ ambsal : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ acacia : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ HH : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ unknown : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ tetradynia : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ efn.neighbor : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
$ shrub.neighbor : int [1:140] NA NA NA NA NA NA NA NA NA NA ...
# A tibble: 2 × 2
treatment mean
<chr> <dbl>
1 C 1.13
2 N 1.39
m1 <-glm(richness ~ treatment + new.segments + x, family ="poisson", data = nozer1)check_overdispersion(m1)
# Overdispersion test
dispersion ratio = 0.207
Pearson's Chi-Squared = 17.764
p-value = 1
No overdispersion detected.
summary(m1)
Call:
glm(formula = richness ~ treatment + new.segments + x, family = "poisson",
data = nozer1)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.064799 0.395392 -0.164 0.870
treatmentN 0.199520 0.192360 1.037 0.300
new.segments 0.003013 0.004796 0.628 0.530
x 0.001100 0.007584 0.145 0.885
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 17.123 on 89 degrees of freedom
Residual deviance: 15.268 on 86 degrees of freedom
AIC: 217.67
Number of Fisher Scoring iterations: 4
Predators
m5 <-glmmTMB(preds ~ new.segments + treatment + solpres + x + (1|year) + (1|uniID), family ="poisson", data = data)summary(m5)
Family: poisson ( log )
Formula:
preds ~ new.segments + treatment + solpres + x + (1 | year) + (1 | uniID)
Data: data
AIC BIC logLik deviance df.resid
1023.2 1056.5 -504.6 1009.2 853
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
year (Intercept) 1.346e-09 3.669e-05
uniID (Intercept) 7.558e-01 8.693e-01
Number of obs: 860, groups: year, 2; uniID, 140
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.812350 0.437683 -4.141 3.46e-05 ***
new.segments -0.006483 0.006339 -1.023 0.306
treatmentN 0.201255 0.221673 0.908 0.364
solpres 0.344011 0.289419 1.189 0.235
x 0.001643 0.008154 0.202 0.840
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
check_overdispersion(m5)
# Overdispersion test
dispersion ratio = 0.832
Pearson's Chi-Squared = 710.010
p-value = 1
No overdispersion detected.
m5 <-glmmTMB(preds ~ new.segments + treatment + pres + x + (1|year) + (1|uniID), family ="poisson", data = data)summary(m5)
Family: poisson ( log )
Formula:
preds ~ new.segments + treatment + pres + x + (1 | year) + (1 | uniID)
Data: data
AIC BIC logLik deviance df.resid
1023.7 1057.0 -504.8 1009.7 853
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
year (Intercept) 1.458e-09 3.819e-05
uniID (Intercept) 7.582e-01 8.707e-01
Number of obs: 860, groups: year, 2; uniID, 140
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.768558 0.443323 -3.989 6.63e-05 ***
new.segments -0.005646 0.006390 -0.883 0.377
treatmentN 0.231290 0.220516 1.049 0.294
pres1 -0.173819 0.193022 -0.901 0.368
x 0.001105 0.008201 0.135 0.893
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m5 <-glmmTMB(preds ~ new.segments + treatment + ants + x + (1|year) + (1|uniID), family ="poisson", data = data)summary(m5)
Family: poisson ( log )
Formula:
preds ~ new.segments + treatment + ants + x + (1 | year) + (1 | uniID)
Data: data
AIC BIC logLik deviance df.resid
1024.4 1057.7 -505.2 1010.4 853
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
year (Intercept) 1.556e-09 3.945e-05
uniID (Intercept) 7.815e-01 8.840e-01
Number of obs: 860, groups: year, 2; uniID, 140
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.822683 0.442948 -4.115 3.87e-05 ***
new.segments -0.005958 0.006458 -0.922 0.356
treatmentN 0.232423 0.222726 1.044 0.297
ants -0.006143 0.018739 -0.328 0.743
x 0.001517 0.008276 0.183 0.855
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
other <-filter(other, family =="Formicidae")other$count <-as.numeric(other$count)other$uniID <-paste(other$PlantID, other$year, other$plant.species)other <-group_by(other, uniID, plant.species, family, genus) %>%summarise(sum =sum(count))
`summarise()` has grouped output by 'uniID', 'plant.species', 'family'. You can
override using the `.groups` argument.
other_wide <- other %>%pivot_wider(names_from ="genus", values_from ="sum")othpt <-filter(plt, Species =="pencilcholla"| Species =="buckhorncholla")othpt$Species <-gsub("cholla", "", othpt$Species)othpt$uniID <-paste(othpt$PlantID, othpt$year, othpt$Species)othpt <-select(othpt, 1:13, 31)other_wide <-left_join(othpt, other_wide, by ="uniID")other_wide <-select(other_wide, 1:14, 17:25)other_wide[,15:23][is.na(other_wide[,15:23])] <-0#join plant info to others#add the dataframes together, make wide and then make long again#other_wide <- select(other_wide, -plant.species)other_wide$uniID <-paste(other_wide$PlantID, other_wide$year, other_wide$Species)#other_wide <- select(other_wide, -family)pts_wide <-select(pts_wide, -family)#make both wides longother_long <-pivot_longer(other_wide, 15:23, names_to ="ant.species", values_to ="abun")pts_long <-pivot_longer(pts_wide, 15:22, names_to ="ant.species", values_to ="abun")all_long <-rbind(pts_long, other_long)all_wide <-pivot_wider(all_long, names_from ="ant.species", values_from ="abun")all_wide[,15:24][is.na(all_wide[,15:24])] <-0all_wide <- all_wide %>%rowwise() %>%mutate(abun =sum(c_across(15:24)))sp <-specnumber(all_wide[,15:24])all_wide$richness <- spall_wide <-mutate(all_wide, anypres =ifelse(abun >0, 1, 0))all_wide <-mutate(all_wide, crempres =ifelse(Crematogaster >0, 1, 0))all_wide <-mutate(all_wide, solpres =ifelse(Solenopsis >0, 1, 0))
Analysis
#control chollas onlysc_wide <-filter(all_wide, Species =="silvercholla")sc_wide <-filter(sc_wide, PlantID !="18trap")sc_wide <-filter(sc_wide, treatment !="N")#sc_wide$treatment <- gsub("", "C", sc_wide$treatment)allcontrol <-filter(all_wide, treatment !="N")control <-filter(all_wide, treatment !="N"& Species !="pencil")#the three species togetherm3p <-glmmTMB(abun ~ Species + x +(1|year), family ="poisson", data = allcontrol)m3 <-glmmTMB(abun ~ Species + x + (1|year), family ="nbinom1", data = allcontrol)m32 <-glmmTMB(abun ~ Species+ x + (1|year), family ="nbinom2", data = allcontrol)AIC(m3p, m3, m32)
Analysis of Deviance Table (Type II Wald chisquare tests)
Response: abun
Chisq Df Pr(>Chisq)
Species 21.6822 2 1.958e-05 ***
x 2.3993 1 0.1214
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
emmeans(m3, pairwise ~ Species)
$emmeans
Species emmean SE df asymp.LCL asymp.UCL
buckhorn 1.169 0.236 Inf 0.706 1.63
pencil -0.259 0.397 Inf -1.037 0.52
silvercholla 1.858 0.244 Inf 1.380 2.34
Results are given on the log (not the response) scale.
Confidence level used: 0.95
$contrasts
contrast estimate SE df z.ratio p.value
buckhorn - pencil 1.428 0.379 Inf 3.770 0.0005
buckhorn - silvercholla -0.688 0.302 Inf -2.276 0.0592
pencil - silvercholla -2.116 0.456 Inf -4.637 <.0001
Results are given on the log (not the response) scale.
P value adjustment: tukey method for comparing a family of 3 estimates
#buckhorn to silver onlym2 <-glmmTMB(richness ~ Species * new.segments + (1|year), family ="poisson", data = control)summary(m2)
Family: poisson ( log )
Formula: richness ~ Species * new.segments + (1 | year)
Data: control
AIC BIC logLik deviance df.resid
284.4 298.3 -137.2 274.4 113
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
year (Intercept) 0.0561 0.2369
Number of obs: 118, groups: year, 2
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.606235 0.306802 -1.976 0.0482 *
Speciessilvercholla 0.435207 0.399710 1.089 0.2762
new.segments 0.003751 0.003917 0.958 0.3383
Speciessilvercholla:new.segments 0.001400 0.007704 0.182 0.8558
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
emmeans(m2, pairwise ~ Species)
NOTE: Results may be misleading due to involvement in interactions
$emmeans
Species emmean SE df asymp.LCL asymp.UCL
buckhorn -0.4421 0.232 Inf -0.897 0.0131
silvercholla 0.0544 0.213 Inf -0.362 0.4712
Results are given on the log (not the response) scale.
Confidence level used: 0.95
$contrasts
contrast estimate SE df z.ratio p.value
buckhorn - silvercholla -0.496 0.204 Inf -2.438 0.0148
Results are given on the log (not the response) scale.
fit <-filter(fit, total.seeds !="na"& total.seeds !=" ")fit$total.seeds <-as.numeric(fit$total.seeds)#blanks mean no non-viable seedsfit$non.viable[is.na(fit$non.viable)] <-0str(fit)
# A tibble: 2 × 2
crempres mean
<dbl> <dbl>
1 0 32.5
2 1 37.8
t.test(seed$viable ~ seed$year.x.x)
Welch Two Sample t-test
data: seed$viable by seed$year.x.x
t = 1.212, df = 293.78, p-value = 0.2265
alternative hypothesis: true difference in means between group 2023 and group 2024 is not equal to 0
95 percent confidence interval:
-1.386471 5.831912
sample estimates:
mean in group 2023 mean in group 2024
35.84713 33.62441
ggplot(seed, aes(ants, total.seeds, fill = treatment)) +geom_smooth(method ="lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 7 rows containing non-finite outside the scale range
(`stat_smooth()`).
Fruit set
# read in fruiting datafruit <-read.csv("Raw Data/cholla_fruitset.csv")str(fruit)
'data.frame': 140 obs. of 5 variables:
$ PlantID: int 1 2 3 4 5 6 7 8 9 10 ...
$ year : int 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
$ fruit : int 3 NA 60 2 NA 7 12 17 8 10 ...
$ partial: int NA 6 NA 2 1 NA NA NA 5 NA ...
$ empty : int NA 3 NA 3 NA 4 NA NA NA NA ...
fruit[is.na(fruit)] <-0fruit <-mutate(fruit, total.fruit = fruit + partial)fruit$uniID <-paste(fruit$PlantID, fruit$year)visits <- visits %>% ungroupfruit <-left_join(visits, fruit, by ="uniID")fruit <-left_join(fruit, ag, by ="uniID")mean(fruit$total.fruit)
[1] 19.97857
m1 <-glm(cbind(total.fruit, buds.x) ~as.factor(crempres) + year.x.x, family ="binomial", data = fruit)summary(m1)
Call:
glm(formula = cbind(total.fruit, buds.x) ~ as.factor(crempres) +
year.x.x, family = "binomial", data = fruit)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.05695 0.04040 -26.163 < 2e-16 ***
as.factor(crempres)1 0.13047 0.04558 2.862 0.004205 **
year.x.x2024 0.16140 0.04582 3.523 0.000427 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 953.21 on 136 degrees of freedom
Residual deviance: 932.87 on 134 degrees of freedom
AIC: 1489.4
Number of Fisher Scoring iterations: 4
#super dispersed#check_overdispersion(m1)m1 <-glm(cbind(total.fruit, buds.x) ~as.factor(crempres) + year.x.x, family ="quasibinomial", data = fruit)summary(m1)
Warning in summary.glm(m1): observations with zero weight not used for
calculating dispersion
Call:
glm(formula = cbind(total.fruit, buds.x) ~ as.factor(crempres) +
year.x.x, family = "quasibinomial", data = fruit)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.0569 0.1034 -10.222 <2e-16 ***
as.factor(crempres)1 0.1305 0.1167 1.118 0.265
year.x.x2024 0.1614 0.1173 1.376 0.171
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for quasibinomial family taken to be 6.551122)
Null deviance: 953.21 on 136 degrees of freedom
Residual deviance: 932.87 on 134 degrees of freedom
AIC: NA
Number of Fisher Scoring iterations: 4
fruit$crepres <-ifelse(fruit$Crematogaster.depilis >0, 1, 0)fruit$crepres <-as.factor(fruit$crepres)m2 <-glmmTMB(total.fruit ~as.factor(crempres) +buds.x + (1|year.x.x), family ="poisson", data = fruit)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
check_overdispersion(m2)
# Overdispersion test
dispersion ratio = 11.357
Pearson's Chi-Squared = 1544.509
p-value = < 0.001
Overdispersion detected.
m2.n <-glmmTMB(total.fruit ~as.factor(crempres) +buds.x + (1|year.x.x), family ="nbinom1", data = fruit)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m2.n)
Family: nbinom1 ( log )
Formula: total.fruit ~ as.factor(crempres) + buds.x + (1 | year.x.x)
Data: fruit
AIC BIC logLik deviance df.resid
1079.7 1094.4 -534.8 1069.7 135
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
year.x.x (Intercept) 0.02837 0.1684
Number of obs: 140, groups: year.x.x, 2
Dispersion parameter for nbinom1 family (): 10.3
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.270976 0.170965 13.283 <2e-16 ***
as.factor(crempres)1 0.162201 0.115741 1.401 0.161
buds.x 0.010799 0.001277 8.458 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m2.n2 <-glmmTMB(total.fruit ~as.factor(crempres) +buds.x + (1|year.x.x), family ="nbinom2", data = fruit)summary(m2.n2)
Family: nbinom2 ( log )
Formula: total.fruit ~ as.factor(crempres) + buds.x + (1 | year.x.x)
Data: fruit
AIC BIC logLik deviance df.resid
1074.3 1089.0 -532.1 1064.3 135
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
year.x.x (Intercept) 9.104e-10 3.017e-05
Number of obs: 140, groups: year.x.x, 2
Dispersion parameter for nbinom2 family (): 1.87
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.02146 0.13169 15.350 < 2e-16 ***
as.factor(crempres)1 0.03315 0.13462 0.246 0.806
buds.x 0.01634 0.00209 7.820 5.27e-15 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1