Data

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.3.3
library(tidyr)
library(performance)
library(glmmTMB)
library(emmeans)
library(vegan)
Loading required package: permute
Loading required package: lattice
Warning: package 'lattice' was built under R version 4.3.3
This is vegan 2.6-4
library(FD)
Loading required package: ade4
Loading required package: ape

Attaching package: 'ape'
The following object is masked from 'package:dplyr':

    where
Loading required package: geometry
library(sf)
Linking to GEOS 3.11.2, GDAL 3.6.2, PROJ 9.2.0; sf_use_s2() is TRUE
library(DHARMa)
Warning: package 'DHARMa' was built under R version 4.3.3
This is DHARMa 0.4.7. For overview type '?DHARMa'. For recent changes, type news(package = 'DHARMa')
library(glmm.hp)
Warning: package 'glmm.hp' was built under R version 4.3.3
Loading required package: MuMIn
Warning: package 'MuMIn' was built under R version 4.3.3
Thank you for using this package! If you use this package in your research, please cite the following references 
Jiangshan Lai, Weijie Zhu, Dongfang Cui, Lingfeng Mao(2023). Extension of the glmm.hp package to Zero-Inflated generalized linear mixed models and multiple regression. Journal of Plant Ecology,16(6):rtad038

Site information

sites <- read.csv("Raw Data/sites.csv")
sites <- st_as_sf(sites, coords=c("Long","Lat"), crs=4326)
# plot(sites)
# st_write(sites, "studysites.shp")
# 
# #read in bioclim data from other repo
env <- terra::rast("F:/CH2_ant-plant_mutualism_synthesis/na_rasters.grd")

#MAP and MAT from Worldclim 
climsites <- terra::extract(env, sites)
sites <- cbind(climsites, sites)
sites <- select(sites, 2, 5, 21:25)
#clean up NDVI values

sites <- rename(sites, MAT = wc2.1_30s_bio_1, MAP = wc2.1_30s_bio_12)
sites <- select(sites, 1:3, 5, 7)
sites <- unique(sites)


ndvi <- read.csv("Raw Data/NDVI.csv")
ndvi$NDVI20231[is.na(ndvi$NDVI20231)] <- 0
ndvi$NDVI20241[is.na(ndvi$NDVI20241)] <- 0
ndvi <- mutate(ndvi, ndvi = NDVI20231 + NDVI20241)
ndvi <- select(ndvi, 1:3, 8)
ndvi <- left_join(ndvi, sites, by = c("Site", "Year"))

Annual abundance and richness

plts <- read.csv("Raw Data/annuals/allplants_IDed.csv")
plts <- dplyr::select(plts, -X)
plts <- dplyr::select(plts, -6)

#not an annual
plts <- filter(plts, species != "Ambrosia.salsola")
str(plts)
'data.frame':   2724 obs. of  7 variables:
 $ Year.NA  : int  2024 2024 2024 2024 2024 2024 2024 2024 2024 2024 ...
 $ Rep.NA   : int  22 4 5 9 11 11 14 16 17 17 ...
 $ Site     : chr  "Tecopa" "HOM" "HOM" "HOM" ...
 $ Date     : chr  "2024-04-16" "2024-04-25" "2024-04-25" "2024-04-25" ...
 $ Microsite: chr  "open" "shrub" "open" "open" ...
 $ species  : chr  "Achyronychia.cooperi" "Acmispon.strigosus" "Acmispon.strigosus" "Acmispon.strigosus" ...
 $ abun     : int  1 1 2 1 1 1 1 1 2 1 ...
plt_wide <- plts %>% pivot_wider(names_from = species, values_from = abun)



unique(plt_wide$Year.NA)
[1] 2024 2023
unique(plt_wide$Rep.NA)
 [1] 22  4  5  9 11 14 16 17 19 20 39 23 24  6 27 26 13 29 25 10 18 28 30  7 21
[26]  2 12 37  1 15  3  8 31 33 35 38 40 32 34 36
unique(plt_wide$Site)
[1] "Tecopa"    "HOM"       "Yucca"     "Cuyama 1"  "Cuyama 2"  "Barstow"  
[7] "Sheephole"
unique(plt_wide$Microsite)
[1] "open"  "shrub"
plt_wide$uniID <- paste(plt_wide$Site, plt_wide$Year.NA, plt_wide$Microsite, plt_wide$Rep.NA)
plt_wide$uniID <- gsub(" ", "", plt_wide$uniID)

plt_wide[is.na(plt_wide)] <- 0


env <- dplyr::select(plt_wide, 1:5, uniID)
comm <- dplyr::select(plt_wide, 6:90)

richness <- specnumber(comm)
abun <- rowSums(comm)

env$rich <- richness
env$abun <- abun

#import plant metadata for zero rows
reps <- read.csv("Raw Data/reps.csv")
reps <- filter(reps, season == "spring")
reps$uniID <- paste(reps$Site, reps$year, reps$Microsite, reps$Rep)
reps$uniID <- gsub(" ", "", reps$uniID)
plt.ag <- left_join(reps, env, by = "uniID")

plt.ag$rich[is.na(plt.ag$rich)] <- 0
plt.ag$abun[is.na(plt.ag$abun)] <- 0





plt.ag <- rename(plt.ag, Site = Site.x, Year = year)
plt.ag$Year <- as.factor(plt.ag$Year)
ndvi$Year <- as.factor(ndvi$Year)
plt.ag <- left_join(plt.ag, ndvi, by = c("Site", "Year"))
Warning in left_join(plt.ag, ndvi, by = c("Site", "Year")): Detected an unexpected many-to-many relationship between `x` and `y`.
ℹ Row 1 of `x` matches multiple rows in `y`.
ℹ Row 1 of `y` matches multiple rows in `x`.
ℹ If a many-to-many relationship is expected, set `relationship =
  "many-to-many"` to silence this warning.
precip <- read.csv("Raw Data/winterprecip_compiled.csv")
precip$Year <- as.factor(precip$Year)


plt.ag <- left_join(plt.ag, precip, by = c("Site", "Year"))
plt.ag <- filter(plt.ag, Season == "spring")


#remove doubled rows
plt.ag <- unique(plt.ag)

#attach provence for invasive/native info

prov <- read.csv("Raw Data/plantprov.csv")
plts <- left_join(plts, prov, by = "species")

prov.ag <- plts %>% group_by(Year.NA, Rep.NA, Site, Microsite, prov) %>% summarise(prov.abun = sum(abun)) %>% ungroup()
`summarise()` has grouped output by 'Year.NA', 'Rep.NA', 'Site', 'Microsite'.
You can override using the `.groups` argument.
str(prov.ag)
tibble [1,528 × 6] (S3: tbl_df/tbl/data.frame)
 $ Year.NA  : int [1:1528] 2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
 $ Rep.NA   : int [1:1528] 1 1 1 1 1 1 1 1 1 1 ...
 $ Site     : chr [1:1528] "Barstow" "Barstow" "Barstow" "Cuyama 1" ...
 $ Microsite: chr [1:1528] "open" "open" "shrub" "open" ...
 $ prov     : chr [1:1528] "invasive" "native" "native" "invasive" ...
 $ prov.abun: int [1:1528] 9 30 4 11 148 0 117 22 2 7 ...
prov.ag <- filter(prov.ag, prov !="") %>% pivot_wider(names_from = prov, values_from = prov.abun)
prov.ag[is.na(prov.ag )] <- 0


plt.ag <- select(plt.ag, 1:6, 10, 16:20)
prov.ag$Year.NA <- as.factor(prov.ag$Year.NA)
plt.ag <- left_join(plt.ag, prov.ag, by = c("Year" = "Year.NA", "Site", "Microsite.x" = "Microsite", "Rep" = "Rep.NA"))

plt.ag$invasive[is.na(plt.ag$invasive)] <- 0
plt.ag$native[is.na(plt.ag$native)] <- 0


#mean plants

mn.plt <- plt.ag %>% group_by(Site, Year) %>% summarise(mean.abun = mean(abun), mean.rich = mean(rich), mean.inv = mean(invasive), mean.native = mean(native))
`summarise()` has grouped output by 'Site'. You can override using the
`.groups` argument.

##CWM Seeds

#read in plant traits

ptraits <- read.csv("clean data/annuallist.csv")
ptraits <- filter(ptraits, species != "Ambrosia.salsola")
ptraits <- dplyr::select(ptraits, 1, 4)


# determine trait coverage by abundance
byspecies <- plt_wide[6:90] %>% colSums()
byspecies <- as.data.frame(byspecies)
byspecies$species <- row.names(byspecies)

sum(byspecies$byspecies)
[1] 50150
tr <- left_join(ptraits, byspecies, by = "species")
sum(tr$byspecies, na.rm = TRUE)
[1] 50147
tr_filter <- filter(tr, seed.weight >= 0)
sum(tr_filter$byspecies, na.rm = TRUE)
[1] 49473
#microsite level CWM

library(FD)
comm <- plt_wide[6:91]

comm <- rename(comm, Ditaxis.lanceolata = Ditaxis.serrata)

row.names(comm) <- comm$uniID
Warning: Setting row names on a tibble is deprecated.
#comm <- dplyr::select(comm, -uniID)
comm <- comm%>%filter(rowSums(across(where(is.numeric)))!=0)


row.names(ptraits) <- ptraits$species
ptraits <- dplyr::select(ptraits, seed.weight)

ptraits <- filter(ptraits, seed.weight > 0)
names.use <- names(comm)[(names(comm) %in% row.names(ptraits))]
#add the uniID to the name vector
names.use <- append(names.use, "uniID")
df.subset <- comm[, names.use]
df.subset <- df.subset%>%filter(rowSums(across(where(is.numeric)))!=0)
sampleIDs <- df.subset$uniID
df.subset <- dplyr::select(df.subset, -uniID)

func.seeds <- dbFD(ptraits, df.subset, w.abun = TRUE)
Warning in is.euclid(x.dist): Zero distance(s)
Warning in is.euclid(x.dist): Zero distance(s)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: Only one continuous trait or dimension in 'x'. FRic was measured as the range, NOT as the convex hull volume. 
FDiv: Cannot not be computed when 'x' contains one single continuous trait or dimension. 
df.subset$cwm.seedweight <- func.seeds$CWM
df.subset$uniID <- sampleIDs

cwm <- cbind(df.subset$uniID, df.subset$cwm.seedweight)
cwm <- rename(cwm, uniID = 'df.subset$uniID')
#join to larger dataframe

env <- left_join(env, cwm, by = "uniID")

#microsite level by provence

#make a vector of each set of species by provence
prov <- filter(prov, species != "Ambrosia.salsola")

inv <- filter(prov, prov == "invasive")
nat <- filter(prov, prov == "native")

invnames <- inv$species
ptraits.inv <- filter(ptraits, row.names(ptraits) %in% invnames)
invnames <- append(invnames, "uniID")

df.subset <- comm[, names.use]
df.subset.inv <- df.subset
df.inv <- df.subset.inv[, invnames]
df.inv <- df.inv%>%filter(rowSums(across(where(is.numeric)))!=0)



uniID <- df.inv$uniID
df.inv <- select(df.inv, -uniID)
row.names(df.inv) <- uniID
Warning: Setting row names on a tibble is deprecated.
#site levels by species

func.inv <- dbFD(ptraits.inv, df.inv, w.abun = TRUE)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: Only one continuous trait or dimension in 'x'. FRic was measured as the range, NOT as the convex hull volume. 
FDiv: Cannot not be computed when 'x' contains one single continuous trait or dimension. 
cwm.inv <- func.inv$CWM
cwm.inv$uniID <- uniID
cwm.inv <- rename(cwm.inv, cwm.inv = seed.weight)


#natives
natnames <- nat$species
ptraits.nat <- filter(ptraits, row.names(ptraits) %in% natnames)

natnames <- append(natnames, "uniID")
print(natnames)
 [1] "Achyronychia.cooperi"      "Acmispon.strigosus"       
 [3] "Acmispon.wrangelianus"     "Aliciella.leptomeria"     
 [5] "Allium.nevadense"          "Amsinckia.tesselata"      
 [7] "Astragalus.didymocarpus"   "Astragalus.lentigonsus"   
 [9] "Astragalus.nuttallianus"   "Calyptridium.monandrum"   
[11] "Camissonia.campestris"     "Castilleja.exserta"       
[13] "Caulanthus.lasiophyllus"   "Chaenactis.carphoclinia"  
[15] "Chaenactis.fremonti"       "Chorizanthe.brevicornu"   
[17] "Chorizanthe.rigida"        "Chylismia.brevipes"       
[19] "Chylismia.caliviformis"    "Cryptantha.nevadensis"    
[21] "Cryptantha.sp"             "Dalea.mollissima"         
[23] "Dasyochloa.pulchella"      "Delphinium.parishii"      
[25] "Descurainia.pinnata"       "Ditaxis.lanceolata"       
[27] "Eleymus.glaucus"           "Eremalche.parryi"         
[29] "Eremothera.boothi"         "Eriastrum.diffusum"       
[31] "Eriastrum.eremicum"        "Eriogonum.gracillimum"    
[33] "Eriogonum.reniforme"       "Eriogonum.trichopes"      
[35] "Eriophyllum.pringlei"      "Eriophyllum.wallacei"     
[37] "Eschscholzia.glyptosperma" "Eschscholzia.minutiflora" 
[39] "Festuca.microstachys"      "Festuca.octoflora"        
[41] "Gilia.clokeyi NA"          "Globemallow. like bells"  
[43] "Lastarriaea.coriacea"      "Lasthenia.californica"    
[45] "Lepidium.lasiocarpum"      "Leptosiphon.liniflorus"   
[47] "Linanthus.demissis"        "Loeseliastrum.schotti"    
[49] "Logfia.depressa"           "Lupinus.arizonicus"       
[51] "Lupinus.flavoculatus"      "Lupinus.microcarpus"      
[53] "Malacothrix.glabrata"      "Menzelia.sp"              
[55] "Monoptilon.bellioides"     "Nama.demissa"             
[57] "Nemacladus.sp"             "Oenothera.cespitosa"      
[59] "Oxytheca.perfoliata"       "Pectocarya.sp"            
[61] "Phacelia.fremontii"        "Phacelia.ramossima"       
[63] "Phacelia.tanacetifolia"    "Pholistoma.membranaceum"  
[65] "Plantago.ovata"            "Poa.secunda"              
[67] "Rafinesquia.californica"   "Rafinesquia.neomexicana"  
[69] "Salvia.carduacea"          "Salvia.columbariae"       
[71] "Stephanomeria.exigua"      "Stipa.pulchra"            
[73] "Stylocline.micropoides"    "uniID"                    
df.subset <- comm[, natnames]
df.subset.nat <- df.subset


natnames <- natnames[(natnames %in% row.names(ptraits))]
natnames <- append(natnames, "uniID")
df.nat <- df.subset.nat[, natnames]
df.nat <- df.nat%>%filter(rowSums(across(where(is.numeric)))!=0)



uniID <- df.nat$uniID
df.nat <- select(df.nat, -uniID)
row.names(df.nat) <- uniID
Warning: Setting row names on a tibble is deprecated.
#site levels by species

func.nat <- dbFD(ptraits.nat, df.nat, w.abun = TRUE)
Warning in is.euclid(x.dist): Zero distance(s)

Warning in is.euclid(x.dist): Zero distance(s)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: Only one continuous trait or dimension in 'x'. FRic was measured as the range, NOT as the convex hull volume. 
FDiv: Cannot not be computed when 'x' contains one single continuous trait or dimension. 
cwm.nat <- func.nat$CWM
cwm.nat$uniID <- uniID
cwm.nat <- rename(cwm.nat, nat.cwm = seed.weight)

#cwm to main dataset

plt.ag <- left_join(plt.ag, cwm, by = "uniID")

plt.ag <- left_join(plt.ag, cwm.inv, by = "uniID")

plt.ag <- left_join(plt.ag, cwm.nat, by = "uniID")




#site level by species
comm.site <- plt_wide %>% group_by(Site, Year.NA) %>% summarise(across(where(is.numeric), sum))
`summarise()` has grouped output by 'Site'. You can override using the
`.groups` argument.
comm.site <- rename(comm.site, Ditaxis.lanceolata = Ditaxis.serrata)

uniID <- paste(comm.site$Site, comm.site$Year.NA)
comm.site <- select(comm.site, 4:88)
Adding missing grouping variables: `Site`
row.names(comm.site) <- uniID
Warning: Setting row names on a tibble is deprecated.
names.use <- names(comm.site)[(names(comm.site) %in% row.names(ptraits))]
#no zero rows at site level
df.subset <- comm.site[, names.use]

func.site <- dbFD(ptraits, df.subset, w.abun = TRUE)
Warning in is.euclid(x.dist): Zero distance(s)

Warning in is.euclid(x.dist): Zero distance(s)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FRic: Only one continuous trait or dimension in 'x'. FRic was measured as the range, NOT as the convex hull volume. 
FDiv: Cannot not be computed when 'x' contains one single continuous trait or dimension. 
#Site levels by provenance
names.use <- names(comm.site)[(names(comm.site) %in% row.names(ptraits.inv))]
#no zero rows at site level
df.subset.inv <- comm.site[, names.use]

func.site.inv <- dbFD(ptraits.inv, df.subset.inv, w.abun = TRUE)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: Only one continuous trait or dimension in 'x'. FRic was measured as the range, NOT as the convex hull volume. 
FDiv: Cannot not be computed when 'x' contains one single continuous trait or dimension. 
names.use <- names(comm.site)[(names(comm.site) %in% row.names(ptraits.nat))]
#no zero rows at site level
df.subset.nat <- comm.site[, names.use]

func.site.nat <- dbFD(ptraits.nat, df.subset.nat, w.abun = TRUE)
Warning in is.euclid(x.dist): Zero distance(s)

Warning in is.euclid(x.dist): Zero distance(s)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: Only one continuous trait or dimension in 'x'. FRic was measured as the range, NOT as the convex hull volume. 
FDiv: Cannot not be computed when 'x' contains one single continuous trait or dimension. 
#join all the site levels to the other plant site level
cwm.site <- func.site$CWM
cwm.site <- rename(cwm.site, cwm.site = seed.weight)

cwm.site.inv <- func.site.inv$CWM
cwm.site.inv <- rename(cwm.site.inv, cwm.site.inv = seed.weight)

cwm.site.nat <- func.site.nat$CWM
cwm.site.nat <- rename(cwm.site.nat, cwm.site.nat = seed.weight)


mn.plt <- cbind(mn.plt, cwm.site, cwm.site.inv, cwm.site.nat)

Seed Removal

seed2023 <- read.csv("Raw Data/seedrates2023.csv")
#526 put out
seed2023 <- filter(seed2023, ending.weight != "disturbed")
seed2023 <- filter(seed2023, ending.weight != "broken")
seed2023 <- filter(seed2023, ending.weight != "was never put out")

seed2023 <- dplyr::select(seed2023, 1:7)

seed2024 <- read.csv("Raw Data/seedsrates2024.csv")
seed2024 <- filter(seed2024, ending.weight != "disturbed")
seed2024 <- filter(seed2024, ending.weight != "not put out" & ending.weight != "never put out")
seed2024$Site <- gsub("yucca", "HOM", seed2024$Site)

seeds <- rbind(seed2023, seed2024)
seeds$ending.weight <- as.numeric(seeds$ending.weight)




unique(seeds$Size)
[1] "small"  "med"    "large"  "medium" "large "
seeds$Size <- gsub(" ", "", seeds$Size)
seeds$Size <- gsub("medium", "med", seeds$Size)
seeds$Year <- as.factor(seeds$Year)

seeds$Site <- gsub(" ", "", seeds$Site)

ndvi$Year <- as.factor(ndvi$Year)
ndvi <- unique(ndvi)
ndvi <- filter(ndvi, Season == "spring")

seeds$Site <- gsub("YuccaGrove", "Yucca", seeds$Site)
seeds$Site <- gsub("Cuyama1", "Cuyama 1", seeds$Site)
seeds$Site <- gsub("Cuyama2", "Cuyama 2", seeds$Site)

seeds <- left_join(seeds, ndvi, by = c("Site", "Year"))
seeds <- unique(seeds)


seeds <- left_join(seeds, precip, by = c("Site", "Year"))

Ant Abundance and Richness - pitfall trap level

arth2 <- read.csv("Raw Data/pitfall_arth.csv")
ants <- dplyr::filter(arth2, Family == "Formicidae")
sum(ants$count)
[1] 629
unique(ants$Site)
[1] "Cuyama 2"  "Cuyama 1"  "Tecopa"    "HOM"       "Sheephole" "Yucca"    
[7] "Barstow"  
unique(ants$Year)
[1] 2023 2024
ants <- filter(ants, Species != "alate")
ants <- filter(ants, Species != "alata")
ants <- filter(ants, Species != "damaged")
ants <- filter(ants, Genus != "damaged")
ants <- filter(ants, Species != "alate/queen")  
ants$Genus <- gsub(" ", "", ants$Genus)

sp <- ants %>% group_by(Genus, Species) %>% summarize(sum(count))
`summarise()` has grouped output by 'Genus'. You can override using the
`.groups` argument.
write.csv(sp, "clean Data/ants_species.csv")
write.csv(ants, "clean Data/ants_only.csv")

ants <- dplyr::select(ants, 1:5, 11)

#make wide
str(ants)
'data.frame':   314 obs. of  6 variables:
 $ Year   : int  2023 2023 2024 2024 2024 2023 2023 2023 2023 2023 ...
 $ Season : chr  "spring" "spring" "spring" "spring" ...
 $ Site   : chr  "HOM" "HOM" "Sheephole" "Sheephole" ...
 $ label  : chr  "S29" "S30" "O19" "O20" ...
 $ count  : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Species: chr  "Aphaenogaster megommata" "Aphaenogaster megommata" "Aphaenogaster megommata" "Aphaenogaster megommata" ...
ants <- ants %>% group_by(Year, Season, Site, label, Species) %>% summarize(abun = sum(count))
`summarise()` has grouped output by 'Year', 'Season', 'Site', 'label'. You can
override using the `.groups` argument.
ants_wide <- pivot_wider(ants, names_from = Species, values_from = abun)

ants_wide[is.na(ants_wide)] <- 0

envants <- dplyr::select(ants_wide, 1:4)
commants <- ants_wide %>% ungroup() %>% dplyr::select(5:29)


richness <- specnumber(commants)
abun <- rowSums(commants)

envants$rich <- richness
envants$abun <- abun

envants <- envants %>% separate(label, into = c("Microsite", "rep"), sep = 1)

envants$Microsite <- gsub("S", "shrub", envants$Microsite)
envants$Microsite <- gsub("O", "open", envants$Microsite)
envants$Year <- as.factor(envants$Year)


#need empty pitfalls to fill in zeroes

reps <- read.csv("Raw Data/reps.csv")
pitsreps <- filter(reps, Pit == "y")
pitsreps$year <- as.factor(pitsreps$year)
pitsreps$Rep <- as.character(pitsreps$Rep)
ptsreps <- left_join(pitsreps, envants, by = c("Site", "year" = "Year", "season" = "Season", "Microsite", "Rep" = "rep"))





ndvi$Year <- as.factor(ndvi$Year)
ptsreps <- left_join(ptsreps, ndvi, by = c("Site", "year" = "Year"))

ptsreps <- left_join(ptsreps, precip, by = c("Site", "year" = "Year"))


ptsreps$rich[is.na(ptsreps$rich)] <- 0
ptsreps$abun[is.na(ptsreps$abun)] <- 0

reps %>% group_by(Pit) %>% summarise(n())
# A tibble: 4 × 2
  Pit   `n()`
  <chr> <int>
1 ""      855
2 "N"      20
3 "n"       6
4 "y"     535
str(reps)
'data.frame':   1416 obs. of  9 variables:
 $ year         : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
 $ Rep          : int  1 1 2 2 3 3 4 4 5 5 ...
 $ Site         : chr  "Tecopa" "Tecopa" "Tecopa" "Tecopa" ...
 $ season       : chr  "spring" "spring" "spring" "spring" ...
 $ Date         : chr  "2023-04-11" "2023-04-11" "2023-04-11" "2023-04-11" ...
 $ Microsite    : chr  "shrub" "open" "shrub" "open" ...
 $ Pit          : chr  "" "" "" "" ...
 $ X            : logi  NA NA NA NA NA NA ...
 $ shrub.species: chr  "" "" "" "" ...

CWM Ants

atraits <- read.csv("Raw Data/anttraits.csv")
atraits <- mutate(atraits, r.mand = mandible/webers)

unique(atraits$ant.species)
 [1] "Dorymyrmex insanus"         "Forelius mccooki"          
 [3] "Messor pergandei"           "Myrmecocystus kennedyi"    
 [5] "Solenopsis xyloni"          "Forelius pruinosis"        
 [7] "Myrmecocystus testaceus"    "Pheidole hyatti"           
 [9] "Solenopsis molesta"         "Myrmecocystus mexicanus"   
[11] "Pogonomyrmex"               "Aphaenogaster megommata"   
[13] "Myrmecocystus lugubris"     "Crematogaster depilis"     
[15] "Leptothorax"                "Monomorium ergotyna/minima"
[17] "Myrmecocystus ewarti"       "Myrmecocystus flaviceps"   
[19] "Myrmecocystus yuma"         "Pheidole vistana"          
[21] "Pogonomyrmex californicus"  "Myrmecocystus semirufus"   
[23] "Myrmecocystus tenuinodis"   "Pheidole desertorum"       
[25] "Pogonomyrmex rugusus"      
unique(atraits$site)
[1] "Barstow"   "Cuyama 1"  "Cuyama 2"  "HOM"       "Sheephole" "Tecopa"   
[7] "Yucca"    
atraits <- atraits %>% group_by(site, ant.species) %>% summarise(r.mand = mean(r.mand), webers = mean(webers))
`summarise()` has grouped output by 'site'. You can override using the
`.groups` argument.
atraits$species.site <- paste(atraits$ant.species, atraits$site)
atraits <- ungroup(atraits) %>% dplyr::select(5, 3, 4)

unique(ants$Site)
[1] "Barstow"   "Cuyama 1"  "Cuyama 2"  "HOM"       "Sheephole" "Tecopa"   
[7] "Yucca"    
#reorder ants data
tr_wide <- ants
tr_wide$species.site <- paste(tr_wide$Species, tr_wide$Site)
tr_wide <- tr_wide %>% mutate(pres = ifelse(abun > 0, 1, 0))
tr_wide <- dplyr::select(tr_wide, 1:4, 7, 8)



tr_wide <- pivot_wider(tr_wide, names_from = species.site, values_from = pres)

tr_wide[is.na(tr_wide)] <- 0



tr_wide$ID <- paste(tr_wide$Year, tr_wide$Season, tr_wide$Site, tr_wide$label)
tr_wide <- tr_wide %>% ungroup() %>% dplyr::select(65, 5:64)

#make a vector of the row names and remove the first value

tr.names <- tr_wide$ID
tr_wide <- tr_wide[,-1]


names.use <- names(tr_wide)[(names(tr_wide) %in% atraits$species.site)]
#add the uniID to the name vector
#names.use <- append(names.use, "uniID")
df.subset <- tr_wide[, names.use, drop = FALSE]
df <- df.subset[,order(names.use), drop = FALSE]
atraits <- atraits[order(atraits$species.site),]
row.names(df) <- tr.names
Warning: Setting row names on a tibble is deprecated.
colnames(df) <- gsub(" ", "", colnames(df))


#fill in missing C. depilis traits with those from other sites
atraits[4,2] <- 0.4389248
atraits[6,2] <- 0.4389248
atraits[4,3] <- 0.885
atraits[6,3] <- 0.885

atr.names <- atraits$species.site
atr.names <- gsub(" ", "", atr.names)
atraits <- atraits[,2:3]
row.names(atraits) <- atr.names
Warning: Setting row names on a tibble is deprecated.
setdiff(row.names(atraits), colnames(df))
character(0)
setdiff(colnames(df), row.names(atraits))
character(0)
identical(row.names(atraits), colnames(df))
[1] TRUE
ck <- cbind(row.names(atraits), colnames(df))
rownames(atraits) == colnames(df)
 [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[31] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[46] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
str(atraits)
tibble [59 × 2] (S3: tbl_df/tbl/data.frame)
 $ r.mand: num [1:59] 0.371 0.362 0.345 0.439 0.439 ...
 $ webers: num [1:59] 1.442 1.629 1.719 0.885 0.885 ...
rownames(atraits) <- atr.names
Warning: Setting row names on a tibble is deprecated.
atraits <- as.data.frame(atraits)
df <- as.data.frame(df)
str(df)
'data.frame':   227 obs. of  59 variables:
 $ AphaenogastermegommataHOM         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ AphaenogastermegommataSheephole   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ AphaenogastermegommataTecopa      : num  0 0 0 0 0 0 0 0 0 0 ...
 $ CrematogasterdepilisSheephole     : num  0 0 0 0 0 0 0 0 0 0 ...
 $ CrematogasterdepilisTecopa        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ CrematogasterdepilisYucca         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusBarstow          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusCuyama2          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusHOM              : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusSheephole        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusTecopa           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusYucca            : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ForeliusmccookiBarstow            : num  0 1 0 0 0 0 0 0 0 0 ...
 $ ForeliusmccookiYucca              : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ForeliuspruinosisCuyama1          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ForeliuspruinosisCuyama2          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ForeliuspruinosisSheephole        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ LeptothoraxSheephole              : num  0 0 0 0 0 0 0 0 0 0 ...
 $ LeptothoraxYucca                  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MessorpergandeiBarstow            : num  1 1 1 1 0 1 0 1 1 1 ...
 $ MessorpergandeiCuyama1            : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MessorpergandeiCuyama2            : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MessorpergandeiHOM                : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MessorpergandeiTecopa             : num  0 0 0 0 0 0 0 0 0 0 ...
 $ Monomoriumergotyna/minimaSheephole: num  0 0 0 0 0 0 0 0 0 0 ...
 $ Monomoriumergotyna/minimaTecopa   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystusewartiSheephole      : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystusflavicepsSheephole   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystusflavicepsYucca       : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystuskennedyiBarstow      : num  0 0 0 0 1 0 1 0 0 0 ...
 $ MyrmecocystuskennedyiCuyama1      : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystuskennedyiCuyama2      : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystuskennedyiHOM          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystuslugubrisHOM          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystusmexicanusCuyama2     : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystusmexicanusHOM         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystusmexicanusYucca       : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystussemirufusTecopa      : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystustenuinodisTecopa     : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystustestaceusCuyama1     : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MyrmecocystusyumaSheephole        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidoledesertorumYucca           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidolehyattiCuyama1             : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidolehyattiCuyama2             : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidolehyattiHOM                 : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidolevistanaSheephole          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PogonomyrmexcalifornicusSheephole : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PogonomyrmexcalifornicusTecopa    : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PogonomyrmexCuyama2               : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PogonomyrmexrugususYucca          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsismolestaCuyama1          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsismolestaCuyama2          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniBarstow           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniCuyama1           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniCuyama2           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniHOM               : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniSheephole         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniTecopa            : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniYucca             : num  0 0 0 0 0 0 0 0 0 0 ...
row.names(df) <- tr.names
rownames(atraits) <- atr.names
func.ants <- dbFD(atraits, df, w.abun = TRUE)
Warning in is.euclid(x.dist): Zero distance(s)
Warning in is.euclid(x.dist): Zero distance(s)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: To respect s > t, FRic could not be calculated for communities with <3 functionally singular species. 
FRic: No dimensionality reduction was required. The 2 PCoA axes were kept as 'traits'. 
FDiv: Could not be calculated for communities with <3 functionally singular species. 
cwmants <- cbind(tr.names, func.ants$CWM)
cwmants$tr.names <- gsub("Cuyama 1", "Cuyama1", cwmants$tr.names)
cwmants$tr.names <- gsub("Cuyama 2", "Cuyama2", cwmants$tr.names)
#make the labels match and join back to trap data

cwmants <- separate(cwmants, col = 1, into = c("year", "season", "Site", "Label"), sep = " ")
Warning: Expected 4 pieces. Additional pieces discarded in 1 rows [171].
cwmants <- separate(cwmants, col = "Label", into = c("Microsite", "Rep"), sep = 1)
cwmants$Microsite <- gsub("S", "shrub", cwmants$Microsite)
cwmants$Microsite <- gsub("O", "open", cwmants$Microsite)

cwmants$Site <- gsub("Cuyama1", "Cuyama 1", cwmants$Site)
cwmants$Site <- gsub("Cuyama2", "Cuyama 2", cwmants$Site)

Granivores only

commgran <- ants_wide %>% ungroup() %>% dplyr::select(5:29)

sp <- read.csv("Raw data/ants_species.csv")
sp <- filter(sp, class != "other")
sp <- sp$Species

names.use <- names(commgran)[(names(commgran) %in% sp)]

df.subset <- commgran[, names.use]
commgran <- df.subset

gr.richness <- specnumber(commgran)
gr.abun <- rowSums(commgran)

envants$rich <- richness
envants$abun <- abun
envants$gr.richness <- gr.richness
envants$gr.abun <- gr.abun


#need empty pitfalls to fill in zeroes


ptsreps <- left_join(pitsreps, envants, by = c("Site", "year" = "Year", "season" = "Season", "Microsite", "Rep" = "rep"))





ndvi$Year <- as.factor(ndvi$Year)
ptsreps <- left_join(ptsreps, ndvi, by = c("Site", "year" = "Year"))

ptsreps <- left_join(ptsreps, precip, by = c("Site", "year" = "Year"))


ptsreps$rich[is.na(ptsreps$rich)] <- 0
ptsreps$abun[is.na(ptsreps$abun)] <- 0

ptsreps$gr.richness[is.na(ptsreps$gr.richness)] <- 0
ptsreps$gr.abun[is.na(ptsreps$gr.abun)] <- 0

#Granivore Trait Calculations

#reorder ants data
tr_wide <- ants
tr <- filter(ants, Species %in% sp)
tr_wide <- tr
tr_wide$species.site <- paste(tr_wide$Species, tr_wide$Site)
tr_wide <- tr_wide %>% mutate(pres = ifelse(abun > 0, 1, 0))
tr_wide <- dplyr::select(tr_wide, 1:4, 7, 8)



tr_wide <- pivot_wider(tr_wide, names_from = species.site, values_from = pres)

tr_wide[is.na(tr_wide)] <- 0



tr_wide$ID <- paste(tr_wide$Year, tr_wide$Season, tr_wide$Site, tr_wide$label)
tr_wide <- tr_wide %>% ungroup() %>% dplyr::select(42, 5:41)

#make a vector of the row names and remove the first value

tr.names <- tr_wide$ID
tr_wide <- tr_wide[,-1]

atraits <- read.csv("Raw Data/anttraits.csv")
atraits <- mutate(atraits, r.mand = mandible/webers)


atraits <- atraits %>% group_by(site, ant.species) %>% summarise(r.mand = mean(r.mand), webers = mean(webers))
`summarise()` has grouped output by 'site'. You can override using the
`.groups` argument.
atraits$species.site <- paste(atraits$ant.species, atraits$site)
atraits <- filter(atraits, ant.species %in% names.use)
atraits <- ungroup(atraits) %>% dplyr::select(5, 3, 4)


unique(ants$Site)
[1] "Barstow"   "Cuyama 1"  "Cuyama 2"  "HOM"       "Sheephole" "Tecopa"   
[7] "Yucca"    
names.use <- names(tr_wide)[(names(tr_wide) %in% atraits$species.site)]
#add the uniID to the name vector
#names.use <- append(names.use, "uniID")
df.subset <- tr_wide[, names.use, drop = FALSE]
df <- df.subset[,order(names.use), drop = FALSE]
atraits <- atraits[order(atraits$species.site),]

row.names(df) <- tr.names
Warning: Setting row names on a tibble is deprecated.
colnames(df) <- gsub(" ", "", colnames(df))



atr.names <- atraits$species.site
atr.names <- gsub(" ", "", atr.names)
atraits <- atraits[,2:3]
row.names(atraits) <- atr.names
Warning: Setting row names on a tibble is deprecated.
setdiff(row.names(atraits), colnames(df))
character(0)
setdiff(colnames(df), row.names(atraits))
character(0)
identical(row.names(atraits), colnames(df))
[1] TRUE
rownames(atraits) <- atr.names
Warning: Setting row names on a tibble is deprecated.
atraits <- as.data.frame(atraits)
df <- as.data.frame(df)
str(df)
'data.frame':   190 obs. of  37 variables:
 $ AphaenogastermegommataHOM        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ AphaenogastermegommataSheephole  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ AphaenogastermegommataTecopa     : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusBarstow         : num  0 0 0 0 0 0 0 0 0 1 ...
 $ DorymyrmexinsanusCuyama2         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusHOM             : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusSheephole       : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusTecopa          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ DorymyrmexinsanusYucca           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ForeliusmccookiBarstow           : num  0 1 0 0 0 0 0 0 0 0 ...
 $ ForeliusmccookiYucca             : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ForeliuspruinosisCuyama1         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ForeliuspruinosisCuyama2         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ForeliuspruinosisSheephole       : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MessorpergandeiBarstow           : num  1 1 1 1 1 1 1 1 0 0 ...
 $ MessorpergandeiCuyama1           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MessorpergandeiCuyama2           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MessorpergandeiHOM               : num  0 0 0 0 0 0 0 0 0 0 ...
 $ MessorpergandeiTecopa            : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidoledesertorumYucca          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidolehyattiCuyama1            : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidolehyattiCuyama2            : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidolehyattiHOM                : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PheidolevistanaSheephole         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PogonomyrmexcalifornicusSheephole: num  0 0 0 0 0 0 0 0 0 0 ...
 $ PogonomyrmexcalifornicusTecopa   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PogonomyrmexCuyama2              : num  0 0 0 0 0 0 0 0 0 0 ...
 $ PogonomyrmexrugususYucca         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsismolestaCuyama1         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsismolestaCuyama2         : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniBarstow          : num  0 0 0 0 0 0 0 0 1 0 ...
 $ SolenopsisxyloniCuyama1          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniCuyama2          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniHOM              : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniSheephole        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniTecopa           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ SolenopsisxyloniYucca            : num  0 0 0 0 0 0 0 0 0 0 ...
row.names(df) <- tr.names
rownames(atraits) <- atr.names

func.gran <- dbFD(atraits, df, w.abun = TRUE)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: To respect s > t, FRic could not be calculated for communities with <3 functionally singular species. 
FRic: No dimensionality reduction was required. The 2 PCoA axes were kept as 'traits'. 
FDiv: Could not be calculated for communities with <3 functionally singular species. 
cwmgran <- cbind(tr.names, func.gran$CWM)
cwmgran$tr.names <- gsub("Cuyama 1", "Cuyama1", cwmgran$tr.names)
cwmgran$tr.names <- gsub("Cuyama 2", "Cuyama2", cwmgran$tr.names)
#make the labels match and join back to trap data

cwmgran <- separate(cwmgran, col = 1, into = c("year", "season", "Site", "Label"), sep = " ")
Warning: Expected 4 pieces. Additional pieces discarded in 1 rows [140].
cwmgran <- separate(cwmgran, col = "Label", into = c("Microsite", "Rep"), sep = 1)
cwmgran$Microsite <- gsub("S", "shrub", cwmgran$Microsite)
cwmgran$Microsite <- gsub("O", "open", cwmgran$Microsite)

cwmgran$Site <- gsub("Cuyama1", "Cuyama 1", cwmgran$Site)
cwmgran$Site <- gsub("Cuyama2", "Cuyama 2", cwmgran$Site)

Site level Ant CWM

atraits <- read.csv("Raw Data/anttraits.csv")
atraits <- mutate(atraits, r.mand = mandible/webers)


atraits <- atraits %>% group_by(site, ant.species) %>% summarise(r.mand = mean(r.mand), webers = mean(webers))
`summarise()` has grouped output by 'site'. You can override using the
`.groups` argument.
atraits$species.site <- paste(atraits$ant.species, atraits$site)

atraits <- ungroup(atraits) %>% dplyr::select(5, 3, 4)




#need the number of good pitfalls, per site, per visit
rps <- ptsreps %>% group_by(year, Site, season) %>% summarise(pit.count = n())
`summarise()` has grouped output by 'year', 'Site'. You can override using the
`.groups` argument.
#reorder ants data
tr_wide <- ants
tr_wide$species.site <- paste(tr_wide$Species, tr_wide$Site)
tr_wide <- tr_wide %>% mutate(pres = ifelse(abun > 0, 1, 0))
tr_wide <- dplyr::select(tr_wide, 1:4, 7, 8)


tr_wide <- tr_wide %>% group_by(Year, Site, Season, species.site) %>% summarise(site.total = sum(pres))
`summarise()` has grouped output by 'Year', 'Site', 'Season'. You can override
using the `.groups` argument.
rps$year <- as.factor(rps$year)
tr_wide$Year <- as.factor(tr_wide$Year)
tr_wide <- left_join(tr_wide, rps, by = c("Year" = "year", "Site", "Season" = "season"))

tr_wide <- mutate(tr_wide, occ = site.total/pit.count)
tr_wide <- select(tr_wide, 1:4, 7)
tr_wide <- pivot_wider(tr_wide, names_from = species.site, values_from = occ)

tr_wide[is.na(tr_wide)] <- 0



tr_wide$ID <- paste(tr_wide$Year, tr_wide$Season, tr_wide$Site)
tr_wide <- tr_wide %>% ungroup() %>% dplyr::select(64, 4:63)

#make a vector of the row names and remove the first value

tr.names <- tr_wide$ID
tr_wide <- tr_wide[,-1]

names(tr_wide) <- gsub(" ", "", names(tr_wide))

names.use <- names(tr_wide)[(names(tr_wide) %in% row.names(atraits$species.site))]
#add the uniID to the name vector
#names.use <- append(names.use, "uniID")
df.subset <- tr_wide[, names.use, drop = FALSE]
df <- df.subset[,order(names.use), drop = FALSE]

atraits <- atraits[order(atraits$species.site),]
tr_wide <- tr_wide[,order(names(tr_wide))]
tr_wide <- select(tr_wide, -LeptothoraxHOM)
row.names(atraits)
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
[31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
[46] "46" "47" "48" "49" "50" "51" "52" "53" "54" "55" "56" "57" "58" "59"
names(tr_wide)
 [1] "AphaenogastermegommataHOM"          "AphaenogastermegommataSheephole"   
 [3] "AphaenogastermegommataTecopa"       "CrematogasterdepilisSheephole"     
 [5] "CrematogasterdepilisTecopa"         "CrematogasterdepilisYucca"         
 [7] "DorymyrmexinsanusBarstow"           "DorymyrmexinsanusCuyama2"          
 [9] "DorymyrmexinsanusHOM"               "DorymyrmexinsanusSheephole"        
[11] "DorymyrmexinsanusTecopa"            "DorymyrmexinsanusYucca"            
[13] "ForeliusmccookiBarstow"             "ForeliusmccookiYucca"              
[15] "ForeliuspruinosisCuyama1"           "ForeliuspruinosisCuyama2"          
[17] "ForeliuspruinosisSheephole"         "LeptothoraxSheephole"              
[19] "LeptothoraxYucca"                   "MessorpergandeiBarstow"            
[21] "MessorpergandeiCuyama1"             "MessorpergandeiCuyama2"            
[23] "MessorpergandeiHOM"                 "MessorpergandeiTecopa"             
[25] "Monomoriumergotyna/minimaSheephole" "Monomoriumergotyna/minimaTecopa"   
[27] "MyrmecocystusewartiSheephole"       "MyrmecocystusflavicepsSheephole"   
[29] "MyrmecocystusflavicepsYucca"        "MyrmecocystuskennedyiBarstow"      
[31] "MyrmecocystuskennedyiCuyama1"       "MyrmecocystuskennedyiCuyama2"      
[33] "MyrmecocystuskennedyiHOM"           "MyrmecocystuslugubrisHOM"          
[35] "MyrmecocystusmexicanusCuyama2"      "MyrmecocystusmexicanusHOM"         
[37] "MyrmecocystusmexicanusYucca"        "MyrmecocystussemirufusTecopa"      
[39] "MyrmecocystustenuinodisTecopa"      "MyrmecocystustestaceusCuyama1"     
[41] "MyrmecocystusyumaSheephole"         "PheidoledesertorumYucca"           
[43] "PheidolehyattiCuyama1"              "PheidolehyattiCuyama2"             
[45] "PheidolehyattiHOM"                  "PheidolevistanaSheephole"          
[47] "PogonomyrmexcalifornicusSheephole"  "PogonomyrmexcalifornicusTecopa"    
[49] "PogonomyrmexCuyama2"                "PogonomyrmexrugususYucca"          
[51] "SolenopsismolestaCuyama1"           "SolenopsismolestaCuyama2"          
[53] "SolenopsisxyloniBarstow"            "SolenopsisxyloniCuyama1"           
[55] "SolenopsisxyloniCuyama2"            "SolenopsisxyloniHOM"               
[57] "SolenopsisxyloniSheephole"          "SolenopsisxyloniTecopa"            
[59] "SolenopsisxyloniYucca"             
#fill in missing C. depilis traits with those from other sites
atraits[4,2] <- 0.4389248
atraits[6,2] <- 0.4389248
atraits[4,3] <- 0.885
atraits[6,3] <- 0.885

atr.names <- atraits$species.site
atr.names <- gsub(" ", "", atr.names)
atraits <- atraits[,2:3]
row.names(atraits) <- atr.names
Warning: Setting row names on a tibble is deprecated.
setdiff(row.names(atraits), colnames(df))
 [1] "AphaenogastermegommataHOM"          "AphaenogastermegommataSheephole"   
 [3] "AphaenogastermegommataTecopa"       "CrematogasterdepilisSheephole"     
 [5] "CrematogasterdepilisTecopa"         "CrematogasterdepilisYucca"         
 [7] "DorymyrmexinsanusBarstow"           "DorymyrmexinsanusCuyama2"          
 [9] "DorymyrmexinsanusHOM"               "DorymyrmexinsanusSheephole"        
[11] "DorymyrmexinsanusTecopa"            "DorymyrmexinsanusYucca"            
[13] "ForeliusmccookiBarstow"             "ForeliusmccookiYucca"              
[15] "ForeliuspruinosisCuyama1"           "ForeliuspruinosisCuyama2"          
[17] "ForeliuspruinosisSheephole"         "LeptothoraxSheephole"              
[19] "LeptothoraxYucca"                   "MessorpergandeiBarstow"            
[21] "MessorpergandeiCuyama1"             "MessorpergandeiCuyama2"            
[23] "MessorpergandeiHOM"                 "MessorpergandeiTecopa"             
[25] "Monomoriumergotyna/minimaSheephole" "Monomoriumergotyna/minimaTecopa"   
[27] "MyrmecocystusewartiSheephole"       "MyrmecocystusflavicepsSheephole"   
[29] "MyrmecocystusflavicepsYucca"        "MyrmecocystuskennedyiBarstow"      
[31] "MyrmecocystuskennedyiCuyama1"       "MyrmecocystuskennedyiCuyama2"      
[33] "MyrmecocystuskennedyiHOM"           "MyrmecocystuslugubrisHOM"          
[35] "MyrmecocystusmexicanusCuyama2"      "MyrmecocystusmexicanusHOM"         
[37] "MyrmecocystusmexicanusYucca"        "MyrmecocystussemirufusTecopa"      
[39] "MyrmecocystustenuinodisTecopa"      "MyrmecocystustestaceusCuyama1"     
[41] "MyrmecocystusyumaSheephole"         "PheidoledesertorumYucca"           
[43] "PheidolehyattiCuyama1"              "PheidolehyattiCuyama2"             
[45] "PheidolehyattiHOM"                  "PheidolevistanaSheephole"          
[47] "PogonomyrmexcalifornicusSheephole"  "PogonomyrmexcalifornicusTecopa"    
[49] "PogonomyrmexCuyama2"                "PogonomyrmexrugususYucca"          
[51] "SolenopsismolestaCuyama1"           "SolenopsismolestaCuyama2"          
[53] "SolenopsisxyloniBarstow"            "SolenopsisxyloniCuyama1"           
[55] "SolenopsisxyloniCuyama2"            "SolenopsisxyloniHOM"               
[57] "SolenopsisxyloniSheephole"          "SolenopsisxyloniTecopa"            
[59] "SolenopsisxyloniYucca"             
setdiff(colnames(df), row.names(atraits))
character(0)
identical(row.names(atraits), colnames(tr_wide))
[1] TRUE
ck <- cbind(row.names(atraits), colnames(df))
rownames(atraits) == colnames(tr_wide)
 [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[31] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[46] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
colnames(tr_wide) == rownames(atraits)
 [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[31] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[46] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
names <- seq(1:59)

names2 <- colnames(tr_wide)

identical(names, names2)
[1] FALSE
row.names(atraits) <- names
Warning: Setting row names on a tibble is deprecated.
names(tr_wide) <- names
Warning: The `value` argument of `names<-` must be a character vector as of tibble
3.0.0.
setdiff(names, names2)
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
[26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
[51] 51 52 53 54 55 56 57 58 59
#set them to numbers

func.ants.site <- dbFD(atraits, tr_wide, w.abun = TRUE)
Warning in is.euclid(x.dist): Zero distance(s)
Warning in is.euclid(x.dist): Zero distance(s)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: To respect s > t, FRic could not be calculated for communities with <3 functionally singular species. 
FRic: No dimensionality reduction was required. The 2 PCoA axes were kept as 'traits'. 
FDiv: Could not be calculated for communities with <3 functionally singular species. 
# 
# 
# 
# 
# 
# 
cwm.ants <- func.ants.site$CWM
cwm.ants <- cbind(tr.names, cwm.ants)

cwm.ants$tr.names <- gsub("Cuyama 1", "Cuyama1", cwm.ants$tr.names)
cwm.ants$tr.names <- gsub("Cuyama 2", "Cuyama2", cwm.ants$tr.names)
cwm.ants <- separate(cwm.ants, col = 1, into = c("year", "season", "Site"), sep = " ")

cwm.ants$Site <- gsub("Cuyama1", "Cuyama 1", cwm.ants$Site)
cwm.ants$Site <- gsub("Cuyama2", "Cuyama 2", cwm.ants$Site)

#Site level Granv CWM

#need to filter out species to just the granivores
gtraits <- read.csv("Raw Data/anttraits.csv")
gtraits <- mutate(gtraits, r.mand = mandible/webers)


gtraits <- gtraits %>% group_by(site, ant.species) %>% summarise(r.mand = mean(r.mand), webers = mean(webers))
`summarise()` has grouped output by 'site'. You can override using the
`.groups` argument.
gtraits$species.site <- paste(gtraits$ant.species, gtraits$site)
gtraits <- filter(gtraits, ant.species %in% sp)
gtraits <- ungroup(gtraits) %>% dplyr::select(5, 3, 4)




#need the number of good pitfalls, per site, per visit
rps <- ptsreps %>% group_by(year, Site, season) %>% summarise(pit.count = n())
`summarise()` has grouped output by 'year', 'Site'. You can override using the
`.groups` argument.
#reorder ants data

tr <- filter(ants, Species %in% sp)
gr_wide <- tr



gr_wide$species.site <- paste(gr_wide$Species, gr_wide$Site)
gr_wide <- gr_wide %>% mutate(pres = ifelse(abun > 0, 1, 0))
gr_wide <- dplyr::select(gr_wide, 1:4, 7, 8)


gr_wide <- gr_wide %>% group_by(Year, Site, Season, species.site) %>% summarise(site.total = sum(pres))
`summarise()` has grouped output by 'Year', 'Site', 'Season'. You can override
using the `.groups` argument.
rps$year <- as.factor(rps$year)
gr_wide$Year <- as.factor(gr_wide$Year)
gr_wide <- left_join(gr_wide, rps, by = c("Year" = "year", "Site", "Season" = "season"))

gr_wide <- mutate(gr_wide, occ = site.total/pit.count)
gr_wide <- select(gr_wide, 1:4, 7)
gr_wide <- pivot_wider(gr_wide, names_from = species.site, values_from = occ)

gr_wide[is.na(gr_wide)] <- 0



gr_wide$ID <- paste(gr_wide$Year, gr_wide$Season, gr_wide$Site)
gr_wide <- gr_wide %>% ungroup() %>% dplyr::select(41, 4:40)

#make a vector of the row names and remove the first value

tr.names <- gr_wide$ID
gr_wide <- gr_wide[,-1]

names(gr_wide) <- gsub(" ", "", names(gr_wide))






gtraits <- gtraits[order(gtraits$species.site),]
gr_wide <- gr_wide[,order(names(gr_wide))]
#gr_wide <- select(gr_wide, -LeptothoraxHOM)


atr.names <- gtraits$species.site
atr.names <- gsub(" ", "", atr.names)

row.names(gtraits) <- atr.names
Warning: Setting row names on a tibble is deprecated.
row.names(gtraits)
 [1] "AphaenogastermegommataHOM"         "AphaenogastermegommataSheephole"  
 [3] "AphaenogastermegommataTecopa"      "DorymyrmexinsanusBarstow"         
 [5] "DorymyrmexinsanusCuyama2"          "DorymyrmexinsanusHOM"             
 [7] "DorymyrmexinsanusSheephole"        "DorymyrmexinsanusTecopa"          
 [9] "DorymyrmexinsanusYucca"            "ForeliusmccookiBarstow"           
[11] "ForeliusmccookiYucca"              "ForeliuspruinosisCuyama1"         
[13] "ForeliuspruinosisCuyama2"          "ForeliuspruinosisSheephole"       
[15] "MessorpergandeiBarstow"            "MessorpergandeiCuyama1"           
[17] "MessorpergandeiCuyama2"            "MessorpergandeiHOM"               
[19] "MessorpergandeiTecopa"             "PheidoledesertorumYucca"          
[21] "PheidolehyattiCuyama1"             "PheidolehyattiCuyama2"            
[23] "PheidolehyattiHOM"                 "PheidolevistanaSheephole"         
[25] "PogonomyrmexcalifornicusSheephole" "PogonomyrmexcalifornicusTecopa"   
[27] "PogonomyrmexCuyama2"               "PogonomyrmexrugususYucca"         
[29] "SolenopsismolestaCuyama1"          "SolenopsismolestaCuyama2"         
[31] "SolenopsisxyloniBarstow"           "SolenopsisxyloniCuyama1"          
[33] "SolenopsisxyloniCuyama2"           "SolenopsisxyloniHOM"              
[35] "SolenopsisxyloniSheephole"         "SolenopsisxyloniTecopa"           
[37] "SolenopsisxyloniYucca"            
names(gr_wide)
 [1] "AphaenogastermegommataHOM"         "AphaenogastermegommataSheephole"  
 [3] "AphaenogastermegommataTecopa"      "DorymyrmexinsanusBarstow"         
 [5] "DorymyrmexinsanusCuyama2"          "DorymyrmexinsanusHOM"             
 [7] "DorymyrmexinsanusSheephole"        "DorymyrmexinsanusTecopa"          
 [9] "DorymyrmexinsanusYucca"            "ForeliusmccookiBarstow"           
[11] "ForeliusmccookiYucca"              "ForeliuspruinosisCuyama1"         
[13] "ForeliuspruinosisCuyama2"          "ForeliuspruinosisSheephole"       
[15] "MessorpergandeiBarstow"            "MessorpergandeiCuyama1"           
[17] "MessorpergandeiCuyama2"            "MessorpergandeiHOM"               
[19] "MessorpergandeiTecopa"             "PheidoledesertorumYucca"          
[21] "PheidolehyattiCuyama1"             "PheidolehyattiCuyama2"            
[23] "PheidolehyattiHOM"                 "PheidolevistanaSheephole"         
[25] "PogonomyrmexcalifornicusSheephole" "PogonomyrmexcalifornicusTecopa"   
[27] "PogonomyrmexCuyama2"               "PogonomyrmexrugususYucca"         
[29] "SolenopsismolestaCuyama1"          "SolenopsismolestaCuyama2"         
[31] "SolenopsisxyloniBarstow"           "SolenopsisxyloniCuyama1"          
[33] "SolenopsisxyloniCuyama2"           "SolenopsisxyloniHOM"              
[35] "SolenopsisxyloniSheephole"         "SolenopsisxyloniTecopa"           
[37] "SolenopsisxyloniYucca"            
gtraits <- gtraits[,2:3]



identical(row.names(gtraits), colnames(gr_wide))
[1] FALSE
names <- seq(1:37)

row.names(gtraits) <- names
Warning: Setting row names on a tibble is deprecated.
names(gr_wide) <- names



#set them to numbers

func.gran.site <- dbFD(gtraits, gr_wide, w.abun = TRUE)
FEVe: Could not be calculated for communities with <3 functionally singular species. 
FDis: Equals 0 in communities with only one functionally singular species. 
FRic: To respect s > t, FRic could not be calculated for communities with <3 functionally singular species. 
FRic: No dimensionality reduction was required. The 2 PCoA axes were kept as 'traits'. 
FDiv: Could not be calculated for communities with <3 functionally singular species. 
cwm.gran.sites <- func.gran.site$CWM
cwm.gran.sites <- cbind(tr.names, cwm.gran.sites)
#cwm.gran.sites <- cwm.gran.sites[,-2]

cwm.gran.sites$tr.names <- gsub("Cuyama 1", "Cuyama1", cwm.gran.sites$tr.names)
cwm.gran.sites$tr.names <- gsub("Cuyama 2", "Cuyama2", cwm.gran.sites$tr.names)
cwm.gran.sites <- separate(cwm.gran.sites, col = 1, into = c("year", "season", "Site"), sep = " ")

cwm.gran.sites$Site <- gsub("Cuyama1", "Cuyama 1", cwm.gran.sites$Site)
cwm.gran.sites$Site <- gsub("Cuyama2", "Cuyama 2", cwm.gran.sites$Site)


mean(cwm.ants$webers)
[1] 1.178508
mean(cwm.gran.sites$webers)
[1] 1.190231
identical(cwm.ants$webers, cwm.gran.sites$webers)
[1] FALSE

Mean ant

sites <- sites %>% mutate(arid = MAP/(MAT + 10))
sites$Year <- as.factor(sites$Year)
plt.ag <- left_join(plt.ag, sites, by = c("Site", "Year"))

plt.ag <- left_join(plt.ag, precip, by = c("Site", "Year"))



#combine pits into means for adding to the dispersal models
mn.ants <- ptsreps %>% group_by(Site, season, year) %>% summarize(mn.abun.ants = mean(abun), mn.rich.ants = mean(rich), mn.gr.abun = mean(gr.abun), mn.gr.rich = mean(gr.richness))
`summarise()` has grouped output by 'Site', 'season'. You can override using
the `.groups` argument.

Combine the datasets

#plt.ag is the main plant dataset


plt.ag <- left_join(plt.ag, filter(cwm.ants, season == "spring"), by = c("Site", "Year" = "year"))

plt.ag <- left_join(plt.ag, filter(cwm.gran.sites, season == "spring"), by = c("Site", "Year" = "year"))

plt.ag <- rename(plt.ag, gr.webers = webers.y, gr.rmand = r.mand.y)



##joining up the pitfall trap data


ptsreps <- left_join(ptsreps, cwmants, by = c("year", "Site", "season", "Microsite", "Rep"))
ptsreps <- select(ptsreps, -X, -Season, shrub.species)

pts <- left_join(ptsreps, mn.plt, by = c("year" = "Year", "Site"))
pts <- left_join(pts, cwmgran, by = c("year", "Site", "season", "Microsite", "Rep"))
pts <- rename(pts, gr.webers = webers.y, gr.rmand = r.mand.y)
pts <- pts %>% mutate(arid = MAP/(MAT + 10))


#join plant data
seeds <- select(seeds, -Season)

seeds <- left_join(seeds, mn.plt, by = c("Site", "Year"))

seeds$Visit <- gsub("Spring", "spring", seeds$Visit)
seeds$Visit <- gsub("Summer", "summer", seeds$Visit)


seeds <- left_join(seeds, cwm.ants, by = c("Year" = "year", "Visit" = "season", "Site"))

seeds <- left_join(seeds, cwm.gran.sites, by = c("Year" = "year", "Visit" = "season", "Site"))
seeds <- rename(seeds, gr.webers = webers.y, gr.rmand = r.mand.y)
seeds <- seeds %>% mutate(arid = MAP/(MAT + 10))

#add mean ant abuns
seeds <- seeds %>% left_join(mn.ants, by = c("Site", "Visit"= "season","Year"  ="year"))




#all site level data in one dataframe

site.env <- pts %>% select(1,3,4, 13:17, 20:26, 29)
site.env <- unique(site.env)

site.env <- left_join(site.env, cwm.ants, by = c("year", "season", "Site"))
site.env <- left_join(site.env, cwm.gran.sites, by = c("year", "season", "Site"))
site.env <- rename(site.env, gr.webers = webers.y, gr.rmand = r.mand.y)

site.env <- left_join(site.env, mn.ants, by = c("Site", "season", "year"))

#Heat map for site

library(corrplot)
corrplot 0.92 loaded
M <- select(site.env, 4:6, 8:20)
M = cor(M)
corrplot(M, method = "color", addCoef.col = 'black', tl.cex = 0.75)

N <- select(site.env, 4:6, 8:24)
N <- drop_na(N)
N <- cor(N)

corrplot(N, method = "color", addCoef.col = 'black', tl.cex = 0.75)

ggplot(site.env, aes(arid, mn.abun.ants)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

group_by(prov, prov) %>% count()
# A tibble: 3 × 2
# Groups:   prov [3]
  prov           n
  <chr>      <int>
1 ""             3
2 "invasive"     9
3 "native"      73
sum(prov.ag$invasive)
[1] 25926
sum(prov.ag$native)
[1] 24088

Plant Models

Annual Richness

m11 <- glmmTMB(rich ~  arid + Microsite.x + (1|Site) + (1|Year), family = "poisson", plt.ag)
summary(m11)
 Family: poisson  ( log )
Formula:          rich ~ arid + Microsite.x + (1 | Site) + (1 | Year)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  3535.1   3559.5  -1762.5   3525.1      975 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.017523 0.13237 
 Year   (Intercept) 0.009622 0.09809 
Number of obs: 980, groups:  Site, 7; Year, 2

Conditional model:
                  Estimate Std. Error z value Pr(>|z|)    
(Intercept)       0.707809   0.112579   6.287 3.23e-10 ***
arid              0.034179   0.007922   4.314 1.60e-05 ***
Microsite.xshrub -0.049220   0.038339  -1.284    0.199    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#adding a random effect for year doesn't improve
m1 <- glmmTMB(rich ~  arid + Microsite.x + (1|Site) + (1|Year), family = poisson(), plt.ag)

#adding ndvi does not improve
m2 <- glmmTMB(rich ~  arid * Microsite.x + ndvi + (1|Site), family = poisson(), plt.ag)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m2)
 Family: poisson  ( log )
Formula:          rich ~ arid * Microsite.x + ndvi + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  3523.3   3552.6  -1755.6   3511.3      974 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.01551  0.1245  
Number of obs: 980, groups:  Site, 7

Conditional model:
                        Estimate Std. Error z value Pr(>|z|)    
(Intercept)            5.722e-01  9.909e-02   5.775 7.68e-09 ***
arid                   4.811e-02  1.053e-02   4.569 4.89e-06 ***
Microsite.xshrub       2.510e-01  6.617e-02   3.793 0.000149 ***
ndvi                   2.254e-06  3.867e-05   0.058 0.953519    
arid:Microsite.xshrub -2.996e-02  5.386e-03  -5.563 2.66e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(m1, m2)
   df      AIC
m1  5 3535.068
m2  6 3523.276
#adding the interaction does improve a lot
m1.int <- glmmTMB(rich ~  arid * Microsite.x + (1|Site), family = "poisson", plt.ag)
summary(m1.int)
 Family: poisson  ( log )
Formula:          rich ~ arid * Microsite.x + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  3521.3   3545.7  -1755.6   3511.3      975 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.01573  0.1254  
Number of obs: 980, groups:  Site, 7

Conditional model:
                       Estimate Std. Error z value Pr(>|z|)    
(Intercept)            0.574745   0.089775   6.402 1.53e-10 ***
arid                   0.048512   0.007976   6.082 1.18e-09 ***
Microsite.xshrub       0.250988   0.066166   3.793 0.000149 ***
arid:Microsite.xshrub -0.029961   0.005386  -5.563 2.66e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m1.int2 <- glmmTMB(rich ~  arid * Microsite.x + ndvi + (1|Site), family = "poisson", plt.ag)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m1.int)
 Family: poisson  ( log )
Formula:          rich ~ arid * Microsite.x + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  3521.3   3545.7  -1755.6   3511.3      975 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.01573  0.1254  
Number of obs: 980, groups:  Site, 7

Conditional model:
                       Estimate Std. Error z value Pr(>|z|)    
(Intercept)            0.574745   0.089775   6.402 1.53e-10 ***
arid                   0.048512   0.007976   6.082 1.18e-09 ***
Microsite.xshrub       0.250988   0.066166   3.793 0.000149 ***
arid:Microsite.xshrub -0.029961   0.005386  -5.563 2.66e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(m1.int, m1.int2)
        df      AIC
m1.int   5 3521.280
m1.int2  6 3523.276
BIC(m1.int, m1.int2)
        df      BIC
m1.int   5 3545.717
m1.int2  6 3552.602
summary(m1.int)
 Family: poisson  ( log )
Formula:          rich ~ arid * Microsite.x + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  3521.3   3545.7  -1755.6   3511.3      975 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.01573  0.1254  
Number of obs: 980, groups:  Site, 7

Conditional model:
                       Estimate Std. Error z value Pr(>|z|)    
(Intercept)            0.574745   0.089775   6.402 1.53e-10 ***
arid                   0.048512   0.007976   6.082 1.18e-09 ***
Microsite.xshrub       0.250988   0.066166   3.793 0.000149 ***
arid:Microsite.xshrub -0.029961   0.005386  -5.563 2.66e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m1.int)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: rich
                   Chisq Df Pr(>Chisq)    
arid             20.6966  1  5.381e-06 ***
Microsite.x       1.5567  1     0.2121    
arid:Microsite.x 30.9427  1  2.658e-08 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
em <- emtrends(m1.int, "Microsite.x", var = "arid")
pairs(em)
 contrast     estimate      SE  df z.ratio p.value
 open - shrub     0.03 0.00539 Inf   5.563  <.0001
summary(em)
 Microsite.x arid.trend      SE  df asymp.LCL asymp.UCL
 open            0.0485 0.00798 Inf   0.03288    0.0641
 shrub           0.0186 0.00808 Inf   0.00271    0.0344

Confidence level used: 0.95 
test(em)
 Microsite.x arid.trend      SE  df z.ratio p.value
 open            0.0485 0.00798 Inf   6.082  <.0001
 shrub           0.0186 0.00808 Inf   2.296  0.0217
plot(em)

Annual Abundance

#annual abundance

m2 <- glmmTMB(abun ~  arid + Microsite.x + (1|Site), family = "poisson", plt.ag)
check_overdispersion(m2)
# Overdispersion test

       dispersion ratio =    27.794
  Pearson's Chi-Squared = 27126.702
                p-value =   < 0.001
Overdispersion detected.
m2.nb <- glmmTMB(abun ~  arid + Microsite.x + (1|Site), family = "nbinom2", plt.ag)
m2.nb1 <- glmmTMB(abun ~  arid + Microsite.x + (1|Site), family = "nbinom1", plt.ag)
m2.int <- glmmTMB(abun ~  arid * Microsite.x + (1|Site), family = "nbinom1", plt.ag)
m2.inb <- glmmTMB(abun ~  arid * Microsite.x + (1|Site), family = "nbinom2", plt.ag)
summary(m2.nb1)
 Family: nbinom1  ( log )
Formula:          abun ~ arid + Microsite.x + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  8860.8   8885.3  -4425.4   8850.8      975 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.3546   0.5955  
Number of obs: 980, groups:  Site, 7

Dispersion parameter for nbinom1 family (): 34.5 

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)       3.11843    0.36480   8.548  < 2e-16 ***
arid              0.08089    0.03391   2.386   0.0171 *  
Microsite.xshrub -0.36739    0.04941  -7.435 1.05e-13 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(m2.nb)
 Family: nbinom2  ( log )
Formula:          abun ~ arid + Microsite.x + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  8933.0   8957.4  -4461.5   8923.0      975 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.5144   0.7172  
Number of obs: 980, groups:  Site, 7

Dispersion parameter for nbinom2 family (): 1.16 

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)       2.85761    0.44171   6.469 9.84e-11 ***
arid              0.09157    0.04126   2.219  0.02646 *  
Microsite.xshrub -0.21499    0.06662  -3.227  0.00125 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(m2.nb1, m2.nb)
       df      AIC
m2.nb1  5 8860.839
m2.nb   5 8932.952
m2.int <- glmmTMB(abun ~  arid * Microsite.x + ndvi + (1|Site), family = "nbinom1", plt.ag) 
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m2.int)
 Family: nbinom1  ( log )
Formula:          abun ~ arid * Microsite.x + ndvi + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  8688.9   8723.1  -4337.4   8674.9      973 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.4141   0.6435  
Number of obs: 980, groups:  Site, 7

Dispersion parameter for nbinom1 family (): 26.9 

Conditional model:
                        Estimate Std. Error z value Pr(>|z|)    
(Intercept)            2.843e+00  3.998e-01   7.111 1.15e-12 ***
arid                   1.627e-01  3.853e-02   4.222 2.42e-05 ***
Microsite.xshrub       4.948e-01  8.415e-02   5.880 4.09e-09 ***
ndvi                  -2.284e-04  5.723e-05  -3.990 6.60e-05 ***
arid:Microsite.xshrub -7.690e-02  6.038e-03 -12.735  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# this model here

m2.int3 <- glmmTMB(abun ~  arid * Microsite.x + ndvi * Microsite.x + (1|Site), family = "nbinom1", plt.ag) 
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
m2.int.hp <- glmmTMB(abun ~  arid : Microsite.x + ndvi:  Microsite.x + (1|Site), family = "nbinom1", plt.ag) 
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
AIC(m2.int, m2.int3)
        df      AIC
m2.int   7 8688.874
m2.int3  8 8587.392
BIC(m2.int, m2.int3)
        df      BIC
m2.int   7 8723.087
m2.int3  8 8626.493
g1 <- glmm.hp(m2.int.hp, commonality = TRUE)
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
plot(g1)

glmm.hp(m2.int.hp)
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
$r.squaredGLMM
                R2m       R2c
delta     0.3281091 0.6445847
lognormal 0.3504380 0.6884509
trigamma  0.2995563 0.5884916

$delta
                 Unique Average.share Individual I.perc(%)
arid:Microsite.x 0.2520        0.0092     0.2612     79.61
ndvi:Microsite.x 0.0577        0.0092     0.0669     20.39

$lognormal
                 Unique Average.share Individual I.perc(%)
arid:Microsite.x 0.2690        0.0145     0.2835     80.91
ndvi:Microsite.x 0.0524        0.0145     0.0669     19.09

$trigamma
                 Unique Average.share Individual I.perc(%)
arid:Microsite.x 0.2308        0.0022     0.2330     77.77
ndvi:Microsite.x 0.0644        0.0022     0.0666     22.23

$variables
[1] "arid:Microsite.x" "ndvi:Microsite.x"

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
summary(m2.int3)
 Family: nbinom1  ( log )
Formula:          abun ~ arid * Microsite.x + ndvi * Microsite.x + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  8587.4   8626.5  -4285.7   8571.4      972 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.4213   0.6491  
Number of obs: 980, groups:  Site, 7

Dispersion parameter for nbinom1 family (): 23.9 

Conditional model:
                        Estimate Std. Error z value Pr(>|z|)    
(Intercept)            3.095e+00  4.033e-01   7.674 1.66e-14 ***
arid                   2.080e-01  3.816e-02   5.450 5.03e-08 ***
Microsite.xshrub      -1.753e-01  1.036e-01  -1.692   0.0907 .  
ndvi                  -4.832e-04  5.178e-05  -9.331  < 2e-16 ***
arid:Microsite.xshrub -1.945e-01  1.289e-02 -15.093  < 2e-16 ***
Microsite.xshrub:ndvi  6.420e-04  6.209e-05  10.340  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m2.int3)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: abun
                   Chisq Df Pr(>Chisq)    
arid              10.860  1  0.0009826 ***
Microsite.x       64.771  1  8.414e-16 ***
ndvi              13.348  1  0.0002588 ***
arid:Microsite.x 227.813  1  < 2.2e-16 ***
Microsite.x:ndvi 106.918  1  < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
em <- emtrends(m2.int3, "Microsite.x", var = "ndvi")
pairs(em)
 contrast      estimate       SE  df z.ratio p.value
 open - shrub -0.000642 6.21e-05 Inf -10.340  <.0001
summary(em)
 Microsite.x ndvi.trend       SE  df asymp.LCL asymp.UCL
 open         -0.000483 5.18e-05 Inf -5.85e-04 -0.000382
 shrub         0.000159 5.00e-05 Inf  6.08e-05  0.000257

Confidence level used: 0.95 
test(em)
 Microsite.x ndvi.trend       SE  df z.ratio p.value
 open         -0.000483 5.18e-05 Inf  -9.331  <.0001
 shrub         0.000159 5.00e-05 Inf   3.175  0.0015
plot(em)

em <- emtrends(m2.int3, "Microsite.x", var = "arid")
pairs(em)
 contrast     estimate     SE  df z.ratio p.value
 open - shrub    0.195 0.0129 Inf  15.093  <.0001
summary(em)
 Microsite.x arid.trend     SE  df asymp.LCL asymp.UCL
 open            0.2080 0.0382 Inf    0.1332    0.2828
 shrub           0.0134 0.0385 Inf   -0.0619    0.0888

Confidence level used: 0.95 
test(em)
 Microsite.x arid.trend     SE  df z.ratio p.value
 open            0.2080 0.0382 Inf   5.450  <.0001
 shrub           0.0134 0.0385 Inf   0.349  0.7267
plot(em)

AIC(m2.int, m2.int3)
        df      AIC
m2.int   7 8688.874
m2.int3  8 8587.392
m2.int2 <- glmmTMB(abun ~  arid * Microsite.x + (1|Site), family = "nbinom1", plt.ag) 

AIC(m2.int, m2.int2, m2.int3)
        df      AIC
m2.int   7 8688.874
m2.int2  6 8717.491
m2.int3  8 8587.392
BIC(m2.int, m2.int2)
        df      BIC
m2.int   7 8723.087
m2.int2  6 8746.816
summary(m2.int)
 Family: nbinom1  ( log )
Formula:          abun ~ arid * Microsite.x + ndvi + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  8688.9   8723.1  -4337.4   8674.9      973 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.4141   0.6435  
Number of obs: 980, groups:  Site, 7

Dispersion parameter for nbinom1 family (): 26.9 

Conditional model:
                        Estimate Std. Error z value Pr(>|z|)    
(Intercept)            2.843e+00  3.998e-01   7.111 1.15e-12 ***
arid                   1.627e-01  3.853e-02   4.222 2.42e-05 ***
Microsite.xshrub       4.948e-01  8.415e-02   5.880 4.09e-09 ***
ndvi                  -2.284e-04  5.723e-05  -3.990 6.60e-05 ***
arid:Microsite.xshrub -7.690e-02  6.038e-03 -12.735  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ggplot(plt.ag, aes(arid, abun, fill = Microsite.x)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(plt.ag, aes(ndvi, abun, fill = Microsite.x)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

em <- emtrends(m2.int2, "Microsite.x", var = "arid")
pairs(em)
 contrast     estimate      SE  df z.ratio p.value
 open - shrub   0.0751 0.00617 Inf  12.177  <.0001
summary(em)
 Microsite.x arid.trend     SE  df asymp.LCL asymp.UCL
 open            0.1187 0.0346 Inf    0.0509     0.187
 shrub           0.0436 0.0346 Inf   -0.0242     0.111

Confidence level used: 0.95 
test(em)
 Microsite.x arid.trend     SE  df z.ratio p.value
 open            0.1187 0.0346 Inf   3.430  0.0006
 shrub           0.0436 0.0346 Inf   1.260  0.2076
plot(em)

Seed size

ggplot(plt.ag, aes(seed.weight, cwm.inv)) + geom_smooth()
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Warning: Removed 208 rows containing non-finite outside the scale range
(`stat_smooth()`).

ggplot(plt.ag, aes(seed.weight, nat.cwm)) + geom_smooth()
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_smooth()`).

ggplot(plt.ag, aes(seed.weight, nat.cwm)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_smooth()`).

ggplot(plt.ag, aes(cwm.inv, nat.cwm)) + geom_smooth()
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Warning: Removed 406 rows containing non-finite outside the scale range
(`stat_smooth()`).

ggplot(plt.ag, aes(cwm.inv, nat.cwm)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 406 rows containing non-finite outside the scale range
(`stat_smooth()`).

cor.test(plt.ag$seed.weight, plt.ag$nat.cwm)

    Pearson's product-moment correlation

data:  plt.ag$seed.weight and plt.ag$nat.cwm
t = 6.8026, df = 692, p-value = 2.226e-11
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.1792766 0.3188408
sample estimates:
      cor 
0.2503589 
cor.test(plt.ag$seed.weight, plt.ag$cwm.inv)

    Pearson's product-moment correlation

data:  plt.ag$seed.weight and plt.ag$cwm.inv
t = 57.306, df = 770, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.8857233 0.9126362
sample estimates:
      cor 
0.9000343 
t.test(plt.ag$native, plt.ag$invasive)

    Welch Two Sample t-test

data:  plt.ag$native and plt.ag$invasive
t = -0.9123, df = 1427.9, p-value = 0.3618
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -5.908244  2.157224
sample estimates:
mean of x mean of y 
 24.57959  26.45510 
#native seed weights
ggplot(plt.ag, aes(arid, log(nat.cwm), fill = Microsite.x)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_smooth()`).

m6 <- glmmTMB(log(nat.cwm) ~ arid + Microsite.x  + gr.webers + gr.rmand + ndvi + (1|Site), plt.ag)
summary(m6)
 Family: gaussian  ( identity )
Formula:          
log(nat.cwm) ~ arid + Microsite.x + gr.webers + gr.rmand + ndvi +  
    (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  1571.1   1607.5   -777.6   1555.1      686 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.06213  0.2493  
 Residual             0.53670  0.7326  
Number of obs: 694, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.537 

Conditional model:
                   Estimate Std. Error z value Pr(>|z|)    
(Intercept)       1.891e-01  7.283e-01   0.260   0.7951    
arid             -1.101e-01  2.048e-02  -5.376 7.63e-08 ***
Microsite.xshrub  4.728e-01  5.665e-02   8.346  < 2e-16 ***
gr.webers        -2.085e-01  3.004e-01  -0.694   0.4877    
gr.rmand         -1.316e+00  1.538e+00  -0.856   0.3923    
ndvi              9.826e-05  5.746e-05   1.710   0.0873 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m7 <- glmmTMB(log(nat.cwm) ~ arid + Microsite.x  + gr.webers + (1|Site), plt.ag)
summary(m7)
 Family: gaussian  ( identity )
Formula:          log(nat.cwm) ~ arid + Microsite.x + gr.webers + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  1571.0   1598.3   -779.5   1559.0      688 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.05416  0.2327  
 Residual             0.54043  0.7351  
Number of obs: 694, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.54 

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      -0.11380    0.46123  -0.247    0.805    
arid             -0.09667    0.01689  -5.724 1.04e-08 ***
Microsite.xshrub  0.47266    0.05683   8.318  < 2e-16 ***
gr.webers        -0.29764    0.29298  -1.016    0.310    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m7)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: log(nat.cwm)
             Chisq Df Pr(>Chisq)    
arid        32.760  1  1.043e-08 ***
Microsite.x 69.185  1  < 2.2e-16 ***
gr.webers    1.032  1     0.3097    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m8 <- glmmTMB(log(nat.cwm) ~ Microsite.x  + arid + gr.webers + gr.rmand + (1|Site), plt.ag)
summary(m8)
 Family: gaussian  ( identity )
Formula:          
log(nat.cwm) ~ Microsite.x + arid + gr.webers + gr.rmand + (1 |      Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  1572.1   1603.9   -779.0   1558.1      687 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.0548   0.2341  
 Residual             0.5396   0.7346  
Number of obs: 694, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.54 

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)       0.41824    0.71580   0.584    0.559    
Microsite.xshrub  0.47156    0.05680   8.303  < 2e-16 ***
arid             -0.09330    0.01734  -5.381 7.43e-08 ***
gr.webers        -0.24106    0.30055  -0.802    0.423    
gr.rmand         -1.48175    1.52860  -0.969    0.332    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m8)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: log(nat.cwm)
              Chisq Df Pr(>Chisq)    
Microsite.x 68.9330  1  < 2.2e-16 ***
arid        28.9498  1  7.428e-08 ***
gr.webers    0.6433  1     0.4225    
gr.rmand     0.9396  1     0.3324    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(m6, m7, m8)
   df      AIC
m6  8 1571.145
m7  6 1571.029
m8  7 1572.088
BIC(m6, m7, m8)
   df      BIC
m6  8 1607.485
m7  6 1598.283
m8  7 1603.885
em <- emtrends(m8, "Microsite.x", var = "arid")
pairs(em)
 contrast     estimate SE  df t.ratio p.value
 open - shrub        0  0 687     NaN     NaN
summary(em)
 Microsite.x arid.trend     SE  df lower.CL upper.CL
 open           -0.0933 0.0173 687   -0.127  -0.0593
 shrub          -0.0933 0.0173 687   -0.127  -0.0593

Confidence level used: 0.95 
test(em)
 Microsite.x arid.trend     SE  df t.ratio p.value
 open           -0.0933 0.0173 687  -5.381  <.0001
 shrub          -0.0933 0.0173 687  -5.381  <.0001
plot(em)

#invasives
m8 <- glmmTMB(log(cwm.inv) ~ arid + Microsite.x  + gr.webers + gr.rmand + ndvi + (1|Site), plt.ag)
summary(m8)
 Family: gaussian  ( identity )
Formula:          
log(cwm.inv) ~ arid + Microsite.x + gr.webers + gr.rmand + ndvi +  
    (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  1604.0   1641.2   -794.0   1588.0      764 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.9005   0.9490  
 Residual             0.4373   0.6613  
Number of obs: 772, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.437 

Conditional model:
                   Estimate Std. Error z value Pr(>|z|)    
(Intercept)      -3.557e+00  8.078e-01  -4.404 1.06e-05 ***
arid              2.395e-01  5.546e-02   4.319 1.57e-05 ***
Microsite.xshrub  3.733e-01  4.775e-02   7.819 5.34e-15 ***
gr.webers         9.466e-03  2.738e-01   0.035 0.972415    
gr.rmand          1.580e+00  1.279e+00   1.236 0.216588    
ndvi             -1.949e-04  5.238e-05  -3.721 0.000198 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m9 <- glmmTMB(log(cwm.inv) ~ arid + Microsite.x  + gr.webers + gr.rmand + (1|Site), plt.ag)
summary(m9)
 Family: gaussian  ( identity )
Formula:          
log(cwm.inv) ~ arid + Microsite.x + gr.webers + gr.rmand + (1 |      Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  1615.7   1648.2   -800.8   1601.7      765 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.7445   0.8628  
 Residual             0.4460   0.6678  
Number of obs: 772, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.446 

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      -3.66145    0.77541  -4.722 2.34e-06 ***
arid              0.20120    0.04977   4.042 5.29e-05 ***
Microsite.xshrub  0.37093    0.04821   7.694 1.43e-14 ***
gr.webers        -0.07522    0.27524  -0.273    0.785    
gr.rmand          1.61836    1.29085   1.254    0.210    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(m8, m9)
   df      AIC
m8  8 1603.993
m9  7 1615.695
BIC(m8, m9)
   df      BIC
m8  8 1641.185
m9  7 1648.238
m8.2 <- glmmTMB(log(cwm.inv) ~ arid + Microsite.x  + gr.webers  + ndvi + (1|Site), plt.ag)
summary(m8.2)
 Family: gaussian  ( identity )
Formula:          
log(cwm.inv) ~ arid + Microsite.x + gr.webers + ndvi + (1 | Site)
Data: plt.ag

     AIC      BIC   logLik deviance df.resid 
  1603.5   1636.1   -794.8   1589.5      765 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.8887   0.9427  
 Residual             0.4382   0.6620  
Number of obs: 772, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.438 

Conditional model:
                   Estimate Std. Error z value Pr(>|z|)    
(Intercept)      -3.048e+00  6.922e-01  -4.404 1.06e-05 ***
arid              2.445e-01  5.498e-02   4.446 8.73e-06 ***
Microsite.xshrub  3.737e-01  4.779e-02   7.818 5.36e-15 ***
gr.webers         1.109e-01  2.615e-01   0.424 0.671496    
ndvi             -1.955e-04  5.244e-05  -3.727 0.000194 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
glmm.hp(m8.2)
$r.squaredGLMM
           R2m       R2c
[1,] 0.6233106 0.8755967

$hierarchical.partitioning
             Unique Average.share Individual I.perc(%)
arid         0.5954        0.0200     0.6154     98.73
Microsite.x  0.0083        0.0020     0.0103      1.65
gr.webers   -0.0037        0.0031    -0.0006     -0.10
ndvi        -0.0210        0.0192    -0.0018     -0.29

$variables
[1] "arid"        "Microsite.x" "gr.webers"   "ndvi"       

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
car::Anova(m8)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: log(cwm.inv)
              Chisq Df Pr(>Chisq)    
arid        18.6553  1  1.566e-05 ***
Microsite.x 61.1303  1  5.342e-15 ***
gr.webers    0.0012  1  0.9724155    
gr.rmand     1.5268  1  0.2165880    
ndvi        13.8468  1  0.0001983 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
glmm.hp(m8)
$r.squaredGLMM
           R2m       R2c
[1,] 0.6210982 0.8761431

$hierarchical.partitioning
             Unique Average.share Individual I.perc(%)
arid         0.5954        0.0186     0.6140     98.86
Microsite.x  0.0084        0.0018     0.0102      1.64
gr.webers   -0.0003        0.0007     0.0004      0.06
gr.rmand    -0.0022        0.0007    -0.0015     -0.24
ndvi        -0.0207        0.0187    -0.0020     -0.32

$variables
[1] "arid"        "Microsite.x" "gr.webers"   "gr.rmand"    "ndvi"       

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
ggplot(plt.ag, aes(arid, log(cwm.inv), fill = Microsite.x)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 208 rows containing non-finite outside the scale range
(`stat_smooth()`).

re <- simulateResiduals(m1)
plot(re)

ggplot(plt.ag, aes(arid, log(seed.weight), fill = Microsite.x)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 88 rows containing non-finite outside the scale range
(`stat_smooth()`).

ggplot(plt.ag, aes(arid, log(nat.cwm), fill = Microsite.x)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_smooth()`).

ggplot(plt.ag, aes(arid, cwm.inv, fill = Microsite.x)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 208 rows containing non-finite outside the scale range
(`stat_smooth()`).

Ant Models

Ant Viz

ggplot(pts, aes(ndvi, gr.abun, fill = Microsite)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(pts, aes(arid, gr.abun, fill = Microsite)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(pts, aes(ndvi, gr.richness, fill = Microsite)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(pts, aes(arid, gr.richness, fill = Microsite)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

Gran Richness

m2 <- glmmTMB(gr.richness ~ Microsite +arid + (1|Site), family = "poisson", pts)

m3 <- glmmTMB(gr.richness ~ ndvi + Microsite +arid + (1|Site), family = "poisson", pts)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
m4 <- glmmTMB(gr.richness ~ ndvi + Microsite +(1|Site), family = "poisson", pts)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
AIC(m2, m3, m4)
   df      AIC
m2  4 909.6973
m3  5 901.7624
m4  4 903.5773
summary(m3)
 Family: poisson  ( log )
Formula:          gr.richness ~ ndvi + Microsite + arid + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
   901.8    923.2   -445.9    891.8      530 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.07504  0.2739  
Number of obs: 535, groups:  Site, 7

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)    -1.4491720  0.2423995  -5.978 2.25e-09 ***
ndvi            0.0004327  0.0001329   3.256  0.00113 ** 
Micrositeshrub  0.0021428  0.1305019   0.016  0.98690    
arid           -0.0738308  0.0339670  -2.174  0.02973 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m2 <- glmmTMB(gr.richness ~ ndvi +Microsite  * arid + (1|Site), family = "poisson", pts)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m2)
 Family: poisson  ( log )
Formula:          gr.richness ~ ndvi + Microsite * arid + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
   903.3    929.0   -445.6    891.3      529 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.07485  0.2736  
Number of obs: 535, groups:  Site, 7

Conditional model:
                      Estimate Std. Error z value Pr(>|z|)    
(Intercept)         -1.5116337  0.2589799  -5.837 5.32e-09 ***
ndvi                 0.0004337  0.0001328   3.265   0.0011 ** 
Micrositeshrub       0.1248514  0.2169446   0.575   0.5650    
arid                -0.0673148  0.0351313  -1.916   0.0554 .  
Micrositeshrub:arid -0.0135250  0.0191025  -0.708   0.4789    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m3 <- glmmTMB(gr.richness ~ ndvi *Microsite + (1|Site), family = "poisson", pts)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m3)
 Family: poisson  ( log )
Formula:          gr.richness ~ ndvi * Microsite + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
   904.6    926.0   -447.3    894.6      530 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.1794   0.4236  
Number of obs: 535, groups:  Site, 7

Conditional model:
                      Estimate Std. Error z value Pr(>|z|)    
(Intercept)         -1.657e+00  3.320e-01  -4.991    6e-07 ***
ndvi                 2.663e-04  9.697e-05   2.746  0.00602 ** 
Micrositeshrub       2.438e-01  2.710e-01   0.900  0.36831    
ndvi:Micrositeshrub -7.834e-05  7.814e-05  -1.002  0.31612    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m3 <- glmmTMB(gr.richness ~ ndvi + Microsite +arid + (1|Site), family = "poisson", pts)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m3)
 Family: poisson  ( log )
Formula:          gr.richness ~ ndvi + Microsite + arid + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
   901.8    923.2   -445.9    891.8      530 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.07504  0.2739  
Number of obs: 535, groups:  Site, 7

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)    -1.4491720  0.2423995  -5.978 2.25e-09 ***
ndvi            0.0004327  0.0001329   3.256  0.00113 ** 
Micrositeshrub  0.0021428  0.1305019   0.016  0.98690    
arid           -0.0738308  0.0339670  -2.174  0.02973 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m3)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: gr.richness
            Chisq Df Pr(>Chisq)   
ndvi      10.6018  1    0.00113 **
Microsite  0.0003  1    0.98690   
arid       4.7246  1    0.02973 * 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
check_collinearity(m3)
# Check for Multicollinearity

Low Correlation

      Term  VIF       VIF 95% CI adj. VIF Tolerance Tolerance 95% CI
      ndvi 3.37 [2.94,     3.91]     1.84      0.30     [0.26, 0.34]
 Microsite 1.00 [1.00,      Inf]     1.00      1.00     [0.00, 1.00]
      arid 3.37 [2.94,     3.91]     1.84      0.30     [0.26, 0.34]
check_overdispersion(m3)
# Overdispersion test

       dispersion ratio =   1.030
  Pearson's Chi-Squared = 545.698
                p-value =   0.309
No overdispersion detected.
performance(m3)
# Indices of model performance

AIC     |    AICc |     BIC | R2 (cond.) | R2 (marg.) |   ICC |  RMSE | Sigma
-----------------------------------------------------------------------------
901.762 | 901.876 | 923.174 |      0.125 |      0.069 | 0.060 | 0.659 | 1.000

AIC     | Score_log | Score_spherical
-------------------------------------
901.762 |    -0.821 |           0.039
glmm.hp(m3)
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
$r.squaredGLMM
                 R2m        R2c
delta     0.03832367 0.06949671
lognormal 0.06870145 0.12458421
trigamma  0.01496137 0.02713118

$delta
           Unique Average.share Individual I.perc(%)
ndvi       0.0339        0.0063     0.0402    104.96
Microsite  0.0000        0.0000     0.0000      0.00
arid      -0.0082        0.0063    -0.0019     -4.96

$lognormal
           Unique Average.share Individual I.perc(%)
ndvi       0.0609        0.0097     0.0706    102.77
Microsite  0.0000        0.0000     0.0000      0.00
arid      -0.0115        0.0096    -0.0019     -2.77

$trigamma
           Unique Average.share Individual I.perc(%)
ndvi       0.0132        0.0028      0.016    106.67
Microsite  0.0000        0.0000      0.000      0.00
arid      -0.0038        0.0028     -0.001     -6.67

$variables
[1] "ndvi"      "Microsite" "arid"     

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
glmm.hp(m3, commonality = TRUE)
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
$r.squaredGLMM
                 R2m        R2c
delta     0.03832367 0.06949671
lognormal 0.06870145 0.12458421
trigamma  0.01496137 0.02713118

$delta
                                    Fractions   % Total
Unique to ndvi                         0.0339     88.35
Unique to Microsite                    0.0000     -0.01
Unique to arid                        -0.0082    -21.48
Common to ndvi, and Microsite          0.0000      0.04
Common to ndvi, and arid               0.0127     33.09
Common to Microsite, and arid          0.0000     -0.02
Common to ndvi, Microsite, and arid    0.0000      0.03
Total                                  0.0383    100.00

$lognormal
                                    Fractions   % Total
Unique to ndvi                         0.0609     88.63
Unique to Microsite                    0.0000     -0.01
Unique to arid                        -0.0115    -16.73
Common to ndvi, and Microsite          0.0000      0.04
Common to ndvi, and arid               0.0193     28.06
Common to Microsite, and arid          0.0000     -0.02
Common to ndvi, Microsite, and arid    0.0000      0.02
Total                                  0.0687    100.00

$trigamma
                                    Fractions   % Total
Unique to ndvi                         0.0132     88.13
Unique to Microsite                    0.0000     -0.01
Unique to arid                        -0.0038    -25.40
Common to ndvi, and Microsite          0.0000      0.04
Common to ndvi, and arid               0.0056     37.25
Common to Microsite, and arid          0.0000     -0.02
Common to ndvi, Microsite, and arid    0.0000      0.03
Total                                  0.0150    100.00

$variables
[1] "ndvi"      "Microsite" "arid"     

$type
[1] "commonality.analysis"

attr(,"class")
[1] "glmmhp"

Gran abundance

m2.1 <- glmmTMB(abun ~ arid+ Microsite   + (1|Site), family = "poisson", pts)

m3.nb <- glmmTMB(gr.abun ~  arid + Microsite  + ndvi +(1|Site), family = "nbinom2", pts)

m3.nb1 <- glmmTMB(gr.abun ~ arid + Microsite  + ndvi +(1|Site) + (1|year), family = "nbinom2", pts)

AIC(m3.nb, m3.nb1)
       df      AIC
m3.nb   6 1294.089
m3.nb1  7 1296.089
#no improvement with year

m4.nb1 <- glmmTMB(gr.abun ~ arid + Microsite  + ndvi +(1|Site), family = "nbinom1", pts)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
m4.nb2 <- glmmTMB(gr.abun ~ arid + Microsite  + ndvi +(1|Site), family = "nbinom2", pts)

AIC(m4.nb1, m4.nb2)
       df      AIC
m4.nb1  6 1279.667
m4.nb2  6 1294.089
m4.int <- glmmTMB(gr.abun ~ arid * Microsite  + ndvi +(1|Site), family = "nbinom1", pts)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m4.int)
 Family: nbinom1  ( log )
Formula:          gr.abun ~ arid * Microsite + ndvi + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
  1281.6   1311.6   -633.8   1267.6      528 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.04855  0.2203  
Number of obs: 535, groups:  Site, 7

Dispersion parameter for nbinom1 family (): 3.53 

Conditional model:
                      Estimate Std. Error z value Pr(>|z|)   
(Intercept)         -0.7680991  0.2664499  -2.883  0.00394 **
arid                -0.0796005  0.0372941  -2.134  0.03281 * 
Micrositeshrub       0.1365227  0.2428167   0.562  0.57395   
ndvi                 0.0004674  0.0001456   3.209  0.00133 **
arid:Micrositeshrub -0.0029802  0.0215771  -0.138  0.89015   
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m4.int2 <- glmmTMB(gr.abun ~ arid + Microsite  * ndvi +(1|Site), family = "nbinom1", pts)
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
summary(m4.int2)
 Family: nbinom1  ( log )
Formula:          gr.abun ~ arid + Microsite * ndvi + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
  1281.6   1311.6   -633.8   1267.6      528 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.04849  0.2202  
Number of obs: 535, groups:  Site, 7

Dispersion parameter for nbinom1 family (): 3.53 

Conditional model:
                      Estimate Std. Error z value Pr(>|z|)   
(Intercept)         -7.953e-01  2.829e-01  -2.811  0.00493 **
arid                -8.118e-02  3.577e-02  -2.269  0.02325 * 
Micrositeshrub       1.864e-01  2.995e-01   0.622  0.53376   
ndvi                 4.812e-04  1.534e-04   3.137  0.00171 **
Micrositeshrub:ndvi -2.556e-05  8.704e-05  -0.294  0.76906   
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
em <- emtrends(m4.int, ~Microsite, var = "arid")
test(em)
 Microsite arid.trend     SE  df z.ratio p.value
 open         -0.0796 0.0373 Inf  -2.134  0.0328
 shrub        -0.0826 0.0375 Inf  -2.204  0.0275
pairs(em)
 contrast     estimate     SE  df z.ratio p.value
 open - shrub  0.00298 0.0216 Inf   0.138  0.8901
glmm.hp(m4.nb1)
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
$r.squaredGLMM
                  R2m         R2c
delta     0.022388652 0.032411982
lognormal 0.057293680 0.082943883
trigamma  0.004629545 0.006702178

$delta
          Unique Average.share Individual I.perc(%)
arid      0.0010         6e-04     0.0016      7.14
Microsite 0.0004         2e-04     0.0006      2.68
ndvi      0.0194         8e-04     0.0202     90.18

$lognormal
          Unique Average.share Individual I.perc(%)
arid      0.0044         7e-04     0.0051      8.89
Microsite 0.0011         4e-04     0.0015      2.61
ndvi      0.0498         1e-03     0.0508     88.50

$trigamma
          Unique Average.share Individual I.perc(%)
arid       1e-04         2e-04     0.0003      6.52
Microsite  1e-04         0e+00     0.0001      2.17
ndvi       4e-03         2e-04     0.0042     91.30

$variables
[1] "arid"      "Microsite" "ndvi"     

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
glmm.hp(m4.nb1, commonality = TRUE)
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.

Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation

Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning: the null model is only correct if all the variables it uses are identical 
to those used in fitting the original model.
$r.squaredGLMM
                  R2m         R2c
delta     0.022388652 0.032411982
lognormal 0.057293680 0.082943883
trigamma  0.004629545 0.006702178

$delta
                                    Fractions   % Total
Unique to arid                         0.0010      4.26
Unique to Microsite                    0.0004      1.89
Unique to ndvi                         0.0194     86.53
Common to arid, and Microsite          0.0000      0.08
Common to arid, and ndvi               0.0013      5.87
Common to Microsite, and ndvi          0.0003      1.28
Common to arid, Microsite, and ndvi    0.0000      0.08
Total                                  0.0224    100.00

$lognormal
                                    Fractions   % Total
Unique to arid                         0.0044      7.63
Unique to Microsite                    0.0011      1.86
Unique to ndvi                         0.0498     86.85
Common to arid, and Microsite          0.0000      0.01
Common to arid, and ndvi               0.0013      2.26
Common to Microsite, and ndvi          0.0007      1.23
Common to arid, Microsite, and ndvi    0.0001      0.16
Total                                  0.0573    100.00

$trigamma
                                    Fractions   % Total
Unique to arid                         0.0001      2.29
Unique to Microsite                    0.0001      1.84
Unique to ndvi                         0.0040     86.37
Common to arid, and Microsite          0.0000      0.12
Common to arid, and ndvi               0.0004      7.97
Common to Microsite, and ndvi          0.0001      1.36
Common to arid, Microsite, and ndvi    0.0000      0.04
Total                                  0.0046    100.00

$variables
[1] "arid"      "Microsite" "ndvi"     

$type
[1] "commonality.analysis"

attr(,"class")
[1] "glmmhp"
performance(m4.nb1)
# Indices of model performance

AIC      |     AICc |      BIC | R2 (cond.) | R2 (marg.) |   ICC |  RMSE
------------------------------------------------------------------------
1279.667 | 1279.826 | 1305.360 |      0.158 |      0.109 | 0.055 | 4.111

AIC      | Sigma | Score_log | Score_spherical
----------------------------------------------
1279.667 | 3.532 |    -2.093 |           0.039
summary(m4.nb1)
 Family: nbinom1  ( log )
Formula:          gr.abun ~ arid + Microsite + ndvi + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
  1279.7   1305.4   -633.8   1267.7      529 

Random effects:

Conditional model:
 Groups Name        Variance Std.Dev.
 Site   (Intercept) 0.04868  0.2206  
Number of obs: 535, groups:  Site, 7

Dispersion parameter for nbinom1 family (): 3.53 

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)   
(Intercept)    -0.7530614  0.2429333  -3.100  0.00194 **
arid           -0.0810578  0.0358152  -2.263  0.02362 * 
Micrositeshrub  0.1098192  0.1467591   0.748  0.45428   
ndvi            0.0004667  0.0001457   3.203  0.00136 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m4.nb1)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: gr.abun
            Chisq Df Pr(>Chisq)   
arid       5.1222  1   0.023622 * 
Microsite  0.5599  1   0.454282   
ndvi      10.2622  1   0.001358 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Webers

cor.test(pts$gr.abun, pts$gr.webers)

    Pearson's product-moment correlation

data:  pts$gr.abun and pts$gr.webers
t = 0.48814, df = 177, p-value = 0.6261
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.1106010  0.1823577
sample estimates:
       cor 
0.03666609 
cor.test(site.env$mn.gr.abun, site.env$gr.webers)

    Pearson's product-moment correlation

data:  site.env$mn.gr.abun and site.env$gr.webers
t = -0.50452, df = 18, p-value = 0.62
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.5327664  0.3423236
sample estimates:
       cor 
-0.1180854 
m5 <- glmmTMB(gr.webers ~ cwm.site.nat + cwm.site.inv + arid + Microsite  + (1|Site), data = pts)
summary(m5)
 Family: gaussian  ( identity )
Formula:          gr.webers ~ cwm.site.nat + cwm.site.inv + arid + Microsite +  
    (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
    52.0     74.3    -19.0     38.0      172 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.02259  0.1503  
 Residual             0.06643  0.2577  
Number of obs: 179, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.0664 

Conditional model:
               Estimate Std. Error z value Pr(>|z|)    
(Intercept)     1.78534    0.23202   7.695 1.42e-14 ***
cwm.site.nat   -0.38787    0.34261  -1.132 0.257589    
cwm.site.inv    0.03326    0.14583   0.228 0.819576    
arid           -0.04412    0.02406  -1.833 0.066734 .  
Micrositeshrub -0.14076    0.03950  -3.564 0.000366 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m5.1 <- glmmTMB(gr.webers ~ cwm.site.nat + cwm.site.inv + arid * Microsite  + (1|Site), data = pts)
  
summary(m5.1)  
 Family: gaussian  ( identity )
Formula:          gr.webers ~ cwm.site.nat + cwm.site.inv + arid * Microsite +  
    (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
    53.7     79.2    -18.8     37.7      171 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.02051  0.1432  
 Residual             0.06652  0.2579  
Number of obs: 179, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.0665 

Conditional model:
                     Estimate Std. Error z value Pr(>|z|)    
(Intercept)          1.788220   0.230903   7.744  9.6e-15 ***
cwm.site.nat        -0.423882   0.352411  -1.203    0.229    
cwm.site.inv         0.018630   0.152660   0.122    0.903    
arid                -0.040375   0.025336  -1.594    0.111    
Micrositeshrub      -0.108644   0.066890  -1.624    0.104    
arid:Micrositeshrub -0.003496   0.005863  -0.596    0.551    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m6 <- glmmTMB(gr.webers ~ cwm.site + arid + Microsite + ndvi + (1|Site), data = pts)



m7 <- glmmTMB(gr.webers ~ cwm.site + arid + Microsite + (1|Site), data = pts)
AIC(m6, m7)
   df      AIC
m6  7 49.75275
m7  6 47.75498
BIC(m6, m7)
   df      BIC
m6  7 72.06445
m7  6 66.87930
gwebers <- glmm.hp(m7, commonality = TRUE)
#model without NDVI is better


summary(m7)
 Family: gaussian  ( identity )
Formula:          gr.webers ~ cwm.site + arid + Microsite + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
    47.8     66.9    -17.9     35.8      173 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept) 0.05877  0.2424  
 Residual             0.06327  0.2515  
Number of obs: 179, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.0633 

Conditional model:
               Estimate Std. Error z value Pr(>|z|)    
(Intercept)     1.43617    0.15302   9.386  < 2e-16 ***
cwm.site        0.17149    0.07096   2.417 0.015670 *  
arid           -0.03627    0.01461  -2.483 0.013023 *  
Micrositeshrub -0.14199    0.03816  -3.721 0.000198 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m7)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: gr.webers
            Chisq Df Pr(>Chisq)    
cwm.site   5.8396  1  0.0156696 *  
arid       6.1659  1  0.0130234 *  
Microsite 13.8476  1  0.0001983 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Mandible length

m9 <- glmmTMB(gr.rmand ~cwm.site.nat*arid + cwm.site.inv + arid + Microsite  + (1|Site), data = pts)
summary(m9)
 Family: gaussian  ( identity )
Formula:          
gr.rmand ~ cwm.site.nat * arid + cwm.site.inv + arid + Microsite +  
    (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
  -664.1   -638.6    340.1   -680.1      171 

Random effects:

Conditional model:
 Groups   Name        Variance  Std.Dev.
 Site     (Intercept) 0.0000867 0.009311
 Residual             0.0012611 0.035512
Number of obs: 179, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.00126 

Conditional model:
                   Estimate Std. Error z value Pr(>|z|)    
(Intercept)        0.380592   0.027030  14.080   <2e-16 ***
cwm.site.nat       0.097032   0.054994   1.764   0.0777 .  
arid               0.004813   0.002254   2.135   0.0327 *  
cwm.site.inv      -0.001310   0.008446  -0.155   0.8768    
Micrositeshrub    -0.005277   0.005408  -0.976   0.3292    
cwm.site.nat:arid -0.016861   0.007333  -2.299   0.0215 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m9 <- glmmTMB(gr.rmand ~cwm.site + arid + Microsite  + ndvi + (1|Site), data = pts)
m10 <- glmmTMB(gr.rmand ~cwm.site + arid + Microsite   + (1|Site), data = pts)
AIC(m9, m10)
    df       AIC
m9   7 -663.8078
m10  6 -665.7974
summary(m10)
 Family: gaussian  ( identity )
Formula:          gr.rmand ~ cwm.site + arid + Microsite + (1 | Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
  -665.8   -646.7    338.9   -677.8      173 

Random effects:

Conditional model:
 Groups   Name        Variance  Std.Dev.
 Site     (Intercept) 0.0002509 0.01584 
 Residual             0.0012392 0.03520 
Number of obs: 179, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.00124 

Conditional model:
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)     0.415955   0.011253   36.96   <2e-16 ***
cwm.site       -0.010199   0.008194   -1.24    0.213    
arid            0.001576   0.001107    1.42    0.155    
Micrositeshrub -0.004692   0.005346   -0.88    0.380    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m10)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: gr.rmand
           Chisq Df Pr(>Chisq)
cwm.site  1.5490  1     0.2133
arid      2.0258  1     0.1547
Microsite 0.7704  1     0.3801
m10 <- glmmTMB(gr.rmand ~cwm.site.inv + cwm.site.nat + arid + Microsite   + (1|Site), data = pts)
summary(m10)
 Family: gaussian  ( identity )
Formula:          
gr.rmand ~ cwm.site.inv + cwm.site.nat + arid + Microsite + (1 |      Site)
Data: pts

     AIC      BIC   logLik deviance df.resid 
  -662.5   -640.2    338.3   -676.5      172 

Random effects:

Conditional model:
 Groups   Name        Variance  Std.Dev.
 Site     (Intercept) 0.0004126 0.02031 
 Residual             0.0012273 0.03503 
Number of obs: 179, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 0.00123 

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)     4.193e-01  2.800e-02  14.975   <2e-16 ***
cwm.site.inv    3.427e-03  1.209e-02   0.283    0.777    
cwm.site.nat   -6.603e-03  3.432e-02  -0.192    0.847    
arid            7.044e-05  2.677e-03   0.026    0.979    
Micrositeshrub -4.813e-03  5.336e-03  -0.902    0.367    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Seed removal rates

seeds <- mutate(seeds, percent = (2 -ending.weight)/0.02)






m7 <- glmmTMB(percent ~ Size + Microsite + ndvi  + mn.gr.abun+ gr.webers+ (1|Year) + (1|Site), seeds)


m8 <- glmmTMB(percent ~ Size + Microsite + ndvi  +  gr.webers + arid + (1|Year) + (1|Site), seeds)

m9 <- glmmTMB(percent ~ Size + Microsite  + mn.gr.abun+ ndvi + (1|Site), seeds)
glmm.hp(m9)
$r.squaredGLMM
           R2m       R2c
[1,] 0.2201239 0.4429465

$hierarchical.partitioning
           Unique Average.share Individual I.perc(%)
Size       0.0081        0.0052     0.0133      6.04
Microsite  0.0010       -0.0003     0.0007      0.32
mn.gr.abun 0.0405       -0.0106     0.0299     13.58
ndvi       0.1814       -0.0052     0.1762     80.05

$variables
[1] "Size"       "Microsite"  "mn.gr.abun" "ndvi"      

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
#m10 <- glmmTMB(percent ~ Size + Microsite + ndvi+ mn.gr.abun + arid + (1|Year) + (1|Site), seeds)
# no convergence
m11 <- glmmTMB(percent ~ Size + Microsite + ndvi + mn.gr.abun +(1|Site), seeds)
AIC(m11)
[1] 5905.323
summary(m11)
 Family: gaussian  ( identity )
Formula:          percent ~ Size + Microsite + ndvi + mn.gr.abun + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5905.3   5940.4  -2944.7   5889.3      585 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept)  462.2   21.50   
 Residual             1155.6   33.99   
Number of obs: 593, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.16e+03 

Conditional model:
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)    61.373877  12.210706   5.026 5.00e-07 ***
Sizemed         7.773261   3.401365   2.285 0.022293 *  
Sizesmall      12.724649   3.435733   3.704 0.000213 ***
Micrositeshrub -1.801134   2.797841  -0.644 0.519732    
ndvi           -0.014451   0.003407  -4.242 2.21e-05 ***
mn.gr.abun      6.129933   1.428712   4.291 1.78e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m12 <- glmmTMB(percent ~ Size + Microsite + mn.gr.abun + arid + (1|Year) + (1|Site), seeds)
summary(m12)
 Family: gaussian  ( identity )
Formula:          
percent ~ Size + Microsite + mn.gr.abun + arid + (1 | Year) +      (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5928.3   5967.8  -2955.2   5910.3      584 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Year     (Intercept)    1.847  1.359  
 Site     (Intercept)  253.891 15.934  
 Residual             1205.203 34.716  
Number of obs: 593, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.21e+03 

Conditional model:
               Estimate Std. Error z value Pr(>|z|)    
(Intercept)     32.7146    10.2801   3.182 0.001461 ** 
Sizemed          7.9060     3.4755   2.275 0.022919 *  
Sizesmall       13.1134     3.5088   3.737 0.000186 ***
Micrositeshrub  -1.7753     2.8571  -0.621 0.534371    
mn.gr.abun       4.9772     1.4590   3.411 0.000646 ***
arid            -0.9013     0.9208  -0.979 0.327663    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(m11, m12)
    df      AIC
m11  8 5905.323
m12  9 5928.321
#keeping year because it improves a teeny bit

#m11.int <- glmmTMB(percent ~ Size*ndvi + Microsite + mn.gr.abun +(1|Year) + (1|Site), seeds)

#summary(m11.int)
#all NA convergence


m11.int <- glmmTMB(percent ~  ndvi + Microsite +Size * mn.gr.abun*cwm.site + arid +  (1|Year) + (1|Site), seeds)

summary(m11.int)
 Family: gaussian  ( identity )
Formula:          
percent ~ ndvi + Microsite + Size * mn.gr.abun * cwm.site + arid +  
    (1 | Year) + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5830.8   5909.7  -2897.4   5794.8      575 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Year     (Intercept) 130.3    11.42   
 Site     (Intercept) 123.7    11.12   
 Residual             989.6    31.46   
Number of obs: 593, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2):  990 

Conditional model:
                                Estimate Std. Error z value Pr(>|z|)    
(Intercept)                    21.639610  12.749205   1.697 0.089634 .  
ndvi                           -0.010077   0.003441  -2.928 0.003409 ** 
Micrositeshrub                 -1.948875   2.589733  -0.753 0.451727    
Sizemed                        19.994897   9.631950   2.076 0.037904 *  
Sizesmall                      32.245537   9.534167   3.382 0.000719 ***
mn.gr.abun                     46.711595   8.434654   5.538 3.06e-08 ***
cwm.site                      -28.262696   8.698480  -3.249 0.001157 ** 
arid                            4.018139   0.913232   4.400 1.08e-05 ***
Sizemed:mn.gr.abun            -14.212566  11.723947  -1.212 0.225410    
Sizesmall:mn.gr.abun          -19.347157  11.586723  -1.670 0.094965 .  
Sizemed:cwm.site               -8.024719   8.105358  -0.990 0.322149    
Sizesmall:cwm.site            -12.729506   8.141876  -1.563 0.117944    
mn.gr.abun:cwm.site           -23.251449   5.249385  -4.429 9.45e-06 ***
Sizemed:mn.gr.abun:cwm.site     7.847827   7.327007   1.071 0.284132    
Sizesmall:mn.gr.abun:cwm.site   8.721238   7.235412   1.205 0.228066    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#models with CWM sizes as interactions


m11.1 <- glmmTMB(percent ~  ndvi + Microsite +Size* gr.rmand + mn.gr.abun + arid + (1|Year) + (1|Site), seeds)
Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')
summary(m11.1)
 Family: gaussian  ( identity )
Formula:          
percent ~ ndvi + Microsite + Size * gr.rmand + mn.gr.abun + arid +  
    (1 | Year) + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5795.0   5851.8  -2884.5   5769.0      569 

Random effects:

Conditional model:
 Groups   Name        Variance  Std.Dev. 
 Year     (Intercept) 1.661e-15 4.075e-08
 Site     (Intercept) 2.658e+02 1.630e+01
 Residual             1.140e+03 3.377e+01
Number of obs: 582, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.14e+03 

Conditional model:
                    Estimate Std. Error z value Pr(>|z|)
(Intercept)         -0.82504        NaN     NaN      NaN
ndvi                -0.01594        NaN     NaN      NaN
Micrositeshrub      -1.44919        NaN     NaN      NaN
Sizemed            -15.28604        NaN     NaN      NaN
Sizesmall          -25.71801        NaN     NaN      NaN
gr.rmand           115.21577        NaN     NaN      NaN
mn.gr.abun           6.97166        NaN     NaN      NaN
arid                 2.07619        NaN     NaN      NaN
Sizemed:gr.rmand    52.90179        NaN     NaN      NaN
Sizesmall:gr.rmand  88.08547        NaN     NaN      NaN
m11.2 <- glmmTMB(percent ~  ndvi + Microsite +Size* gr.webers + mn.gr.abun + arid + (1|Year) + (1|Site), seeds)
Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')
summary(m11.2)
 Family: gaussian  ( identity )
Formula:          percent ~ ndvi + Microsite + Size * gr.webers + mn.gr.abun +  
    arid + (1 | Year) + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5796.0   5852.8  -2885.0   5770.0      569 

Random effects:

Conditional model:
 Groups   Name        Variance  Std.Dev. 
 Year     (Intercept) 1.342e-30 1.158e-15
 Site     (Intercept) 2.280e+02 1.510e+01
 Residual             1.144e+03 3.383e+01
Number of obs: 582, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.14e+03 

Conditional model:
                    Estimate Std. Error z value Pr(>|z|)
(Intercept)         17.73174        NaN     NaN      NaN
ndvi                -0.01744        NaN     NaN      NaN
Micrositeshrub      -1.27994        NaN     NaN      NaN
Sizemed             -2.82118        NaN     NaN      NaN
Sizesmall           13.60998        NaN     NaN      NaN
gr.webers           22.18964        NaN     NaN      NaN
mn.gr.abun           4.67908        NaN     NaN      NaN
arid                 3.22514        NaN     NaN      NaN
Sizemed:gr.webers    8.04723        NaN     NaN      NaN
Sizesmall:gr.webers -1.58343        NaN     NaN      NaN
m11.4 <- glmmTMB(percent ~  ndvi*Size + Microsite + mn.gr.abun + arid  +(1|Year) + (1|Site), seeds)
summary(m11.4)
 Family: gaussian  ( identity )
Formula:          percent ~ ndvi * Size + Microsite + mn.gr.abun + arid + (1 |  
    Year) + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5907.6   5960.2  -2941.8   5883.6      581 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Year     (Intercept)    8.242  2.871  
 Site     (Intercept)  316.672 17.795  
 Residual             1147.086 33.869  
Number of obs: 593, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.15e+03 

Conditional model:
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)     4.986e+01  1.226e+01   4.066 4.78e-05 ***
ndvi           -1.828e-02  3.643e-03  -5.018 5.23e-07 ***
Sizemed         2.700e+00  6.721e+00   0.402   0.6878    
Sizesmall       1.294e+01  6.911e+00   1.873   0.0611 .  
Micrositeshrub -1.800e+00  2.788e+00  -0.646   0.5185    
mn.gr.abun      5.992e+00  1.434e+00   4.179 2.93e-05 ***
arid            2.535e+00  1.223e+00   2.072   0.0383 *  
ndvi:Sizemed    1.955e-03  2.223e-03   0.879   0.3792    
ndvi:Sizesmall -7.708e-05  2.326e-03  -0.033   0.9736    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m11.5 <- glmmTMB(percent ~  ndvi +Size * Microsite + mn.gr.abun + arid + (1|Year) + (1|Site), seeds)
summary(m11.5)
 Family: gaussian  ( identity )
Formula:          percent ~ ndvi + Size * Microsite + mn.gr.abun + arid + (1 |  
    Year) + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5908.3   5960.9  -2942.2   5884.3      581 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Year     (Intercept)    8.372  2.893  
 Site     (Intercept)  317.042 17.806  
 Residual             1148.474 33.889  
Number of obs: 593, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.15e+03 

Conditional model:
                          Estimate Std. Error z value Pr(>|z|)    
(Intercept)              49.273633  12.008714   4.103 4.08e-05 ***
ndvi                     -0.017587   0.003447  -5.102 3.37e-07 ***
Sizemed                   6.326341   4.809753   1.315   0.1884    
Sizesmall                10.885853   4.928292   2.209   0.0272 *  
Micrositeshrub           -3.966646   4.759919  -0.833   0.4047    
mn.gr.abun                5.955153   1.434722   4.151 3.31e-05 ***
arid                      2.527448   1.224098   2.065   0.0389 *  
Sizemed:Micrositeshrub    3.008232   6.775506   0.444   0.6571    
Sizesmall:Micrositeshrub  3.565333   6.835864   0.522   0.6020    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#m11.6 <- glmmTMB(percent ~  ndvi + Microsite + mn.gr.abun + Size *arid + (1|Year) + (1|Site), seeds)
#summary(m11.6)
#causes warnings

m11.3 <- glmmTMB(percent ~  ndvi + Microsite +Size* cwm.site + mn.gr.abun + arid + (1|Year) + (1|Site), seeds)
summary(m11.3)
 Family: gaussian  ( identity )
Formula:          
percent ~ ndvi + Microsite + Size * cwm.site + mn.gr.abun + arid +  
    (1 | Year) + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5855.8   5912.8  -2914.9   5829.8      580 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Year     (Intercept)  124.0   11.13   
 Site     (Intercept)  152.4   12.35   
 Residual             1048.6   32.38   
Number of obs: 593, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.05e+03 

Conditional model:
                     Estimate Std. Error z value Pr(>|z|)    
(Intercept)         45.937723  11.858962   3.874 0.000107 ***
ndvi                -0.006671   0.003509  -1.901 0.057296 .  
Micrositeshrub      -1.901960   2.665266  -0.714 0.475469    
Sizemed             10.569459   4.873859   2.169 0.030113 *  
Sizesmall           19.901472   4.888747   4.071 4.68e-05 ***
cwm.site           -48.566210   7.662037  -6.339 2.32e-10 ***
mn.gr.abun           7.612249   1.382706   5.505 3.68e-08 ***
arid                 3.684755   0.974901   3.780 0.000157 ***
Sizemed:cwm.site    -3.424763   5.091937  -0.673 0.501211    
Sizesmall:cwm.site -10.265629   5.122872  -2.004 0.045083 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#seed size is significant

m11.7 <- glmmTMB(percent ~  ndvi + Microsite + mn.gr.abun :Size + arid + cwm.site + (1|Year) + (1|Site), seeds)
summary(m11.7)
 Family: gaussian  ( identity )
Formula:          
percent ~ ndvi + Microsite + mn.gr.abun:Size + arid + cwm.site +  
    (1 | Year) + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5870.0   5918.3  -2924.0   5848.0      582 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Year     (Intercept)  119.8   10.95   
 Site     (Intercept)  149.2   12.22   
 Residual             1082.1   32.90   
Number of obs: 593, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.08e+03 

Conditional model:
                       Estimate Std. Error z value Pr(>|z|)    
(Intercept)           55.526010  11.432701   4.857 1.19e-06 ***
ndvi                  -0.006761   0.003556  -1.901 0.057264 .  
Micrositeshrub        -1.734046   2.707319  -0.641 0.521846    
arid                   3.711047   0.976733   3.799 0.000145 ***
cwm.site             -52.660360   7.236282  -7.277 3.41e-13 ***
mn.gr.abun:Sizelarge   6.449576   1.856689   3.474 0.000513 ***
mn.gr.abun:Sizemed     8.583828   1.983874   4.327 1.51e-05 ***
mn.gr.abun:Sizesmall   7.778167   1.865440   4.170 3.05e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
glmm.hp(m11.7)
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
$r.squaredGLMM
           R2m       R2c
[1,] 0.2516907 0.4006957

$hierarchical.partitioning
                 Unique Average.share Individual I.perc(%)
ndvi            -0.0103        0.0615     0.0512     20.35
Microsite        0.0005        0.0068     0.0073      2.90
mn.gr.abun:Size  0.0359        0.0030     0.0389     15.46
arid            -0.1619        0.0920    -0.0699    -27.78
cwm.site         0.1566        0.0675     0.2241     89.07

$variables
[1] "ndvi"            "Microsite"       "mn.gr.abun:Size" "arid"           
[5] "cwm.site"       

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
#both abundance and cwm.site are significant interactions, but cwm becomes insignificant when included alongside abundance

m11.8 <- glmmTMB(percent ~  Microsite + mn.gr.abun * Size + arid + cwm.site*Size + (1|Year) + (1|Site), seeds)
summary(m11.8)
 Family: gaussian  ( identity )
Formula:          
percent ~ Microsite + mn.gr.abun * Size + arid + cwm.site * Size +  
    (1 | Year) + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5857.7   5919.1  -2914.8   5829.7      579 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Year     (Intercept)  136.5   11.68   
 Site     (Intercept)  155.7   12.48   
 Residual             1047.9   32.37   
Number of obs: 593, groups:  Year, 2; Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.05e+03 

Conditional model:
                     Estimate Std. Error z value Pr(>|z|)    
(Intercept)            39.797     11.934   3.335 0.000853 ***
Micrositeshrub         -1.875      2.664  -0.704 0.481581    
mn.gr.abun             10.221      2.263   4.517 6.27e-06 ***
Sizemed                11.736      5.128   2.288 0.022111 *  
Sizesmall              22.742      5.108   4.452 8.49e-06 ***
arid                    2.710      0.840   3.226 0.001254 ** 
cwm.site              -55.974      7.375  -7.590 3.21e-14 ***
mn.gr.abun:Sizemed     -2.214      3.241  -0.683 0.494520    
mn.gr.abun:Sizesmall   -6.001      3.146  -1.908 0.056425 .  
Sizemed:cwm.site       -1.795      5.553  -0.323 0.746501    
Sizesmall:cwm.site     -5.474      5.668  -0.966 0.334153    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(m11.3, m11.7, m11.8)
      df      AIC
m11.3 13 5855.759
m11.7 11 5870.018
m11.8 14 5857.671
m11.7 <- glmmTMB(percent ~  Microsite + mn.gr.abun:Size + arid +(1|Site), seeds)
glmm.hp(m11.7)
$r.squaredGLMM
            R2m       R2c
[1,] 0.03393151 0.1992513

$hierarchical.partitioning
                Unique Average.share Individual I.perc(%)
Microsite       0.0004         0e+00     0.0004      1.18
mn.gr.abun:Size 0.0191         6e-04     0.0197     57.94
arid            0.0132         7e-04     0.0139     40.88

$variables
[1] "Microsite"       "mn.gr.abun:Size" "arid"           

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
m11.8 <- glmmTMB(percent ~  Microsite + mn.gr.abun:Size + ndvi +(1|Site), seeds)
glmm.hp(m11.8)
$r.squaredGLMM
           R2m       R2c
[1,] 0.2122178 0.4394797

$hierarchical.partitioning
                Unique Average.share Individual I.perc(%)
Microsite       0.0009       -0.0003     0.0006      0.28
mn.gr.abun:Size 0.0405       -0.0101     0.0304     14.33
ndvi            0.1915       -0.0103     0.1812     85.39

$variables
[1] "Microsite"       "mn.gr.abun:Size" "ndvi"           

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
m11.9 <- glmmTMB(percent ~  Microsite + mn.gr.abun:Size + arid + ndvi +(1|Site), seeds)
glmm.hp(m11.9)
$r.squaredGLMM
            R2m       R2c
[1,] 0.09339005 0.2850194

$hierarchical.partitioning
                 Unique Average.share Individual I.perc(%)
Microsite        0.0006       -0.0001     0.0005      0.54
mn.gr.abun:Size  0.0329       -0.0052     0.0277     29.66
arid            -0.1188        0.0677    -0.0511    -54.71
ndvi             0.0595        0.0568     0.1163    124.52

$variables
[1] "Microsite"       "mn.gr.abun:Size" "arid"            "ndvi"           

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
AIC(m11.7, m11.8, m11.9)
      df      AIC
m11.7  8 5939.436
m11.8  8 5918.252
m11.9  9 5916.348
BIC(m11.7, m11.8, m11.9)
      df      BIC
m11.7  8 5974.518
m11.8  8 5953.333
m11.9  9 5955.815
summary(m11.9)
 Family: gaussian  ( identity )
Formula:          
percent ~ Microsite + mn.gr.abun:Size + arid + ndvi + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5916.3   5955.8  -2949.2   5898.3      584 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept)  315.9   17.77   
 Residual             1178.7   34.33   
Number of obs: 593, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.18e+03 

Conditional model:
                      Estimate Std. Error z value Pr(>|z|)    
(Intercept)          54.344824  11.511441   4.721 2.35e-06 ***
Micrositeshrub       -1.622044   2.825394  -0.574 0.565904    
arid                  2.556661   1.226503   2.085 0.037114 *  
ndvi                 -0.017472   0.003466  -5.041 4.62e-07 ***
mn.gr.abun:Sizelarge  4.984393   1.916659   2.601 0.009307 ** 
mn.gr.abun:Sizemed    7.175519   2.052901   3.495 0.000474 ***
mn.gr.abun:Sizesmall  6.348979   1.929251   3.291 0.000999 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m11.9)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: percent
                  Chisq Df Pr(>Chisq)    
Microsite        0.3296  1  0.5659037    
arid             4.3452  1  0.0371136 *  
ndvi            25.4146  1  4.624e-07 ***
mn.gr.abun:Size 18.8703  3  0.0002908 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
glmm.hp(m11.9)
$r.squaredGLMM
            R2m       R2c
[1,] 0.09339005 0.2850194

$hierarchical.partitioning
                 Unique Average.share Individual I.perc(%)
Microsite        0.0006       -0.0001     0.0005      0.54
mn.gr.abun:Size  0.0329       -0.0052     0.0277     29.66
arid            -0.1188        0.0677    -0.0511    -54.71
ndvi             0.0595        0.0568     0.1163    124.52

$variables
[1] "Microsite"       "mn.gr.abun:Size" "arid"            "ndvi"           

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
m11.8 <- glmmTMB(percent ~  Microsite + mn.gr.abun*Size + ndvi +(1|Site), seeds)
summary(m11.8)
 Family: gaussian  ( identity )
Formula:          percent ~ Microsite + mn.gr.abun * Size + ndvi + (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5903.1   5946.9  -2941.5   5883.1      583 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept)  462.6   21.51   
 Residual             1143.4   33.81   
Number of obs: 593, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.14e+03 

Conditional model:
                      Estimate Std. Error z value Pr(>|z|)    
(Intercept)          58.360622  12.303961   4.743 2.10e-06 ***
Micrositeshrub       -1.739437   2.783102  -0.625   0.5320    
mn.gr.abun            9.336897   2.211607   4.222 2.42e-05 ***
Sizemed              10.027674   4.554164   2.202   0.0277 *  
Sizesmall            20.141091   4.564494   4.413 1.02e-05 ***
ndvi                 -0.014549   0.003392  -4.289 1.80e-05 ***
mn.gr.abun:Sizemed   -2.174547   3.103977  -0.701   0.4836    
mn.gr.abun:Sizesmall -7.272727   2.969092  -2.449   0.0143 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
car::Anova(m11.8)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: percent
                  Chisq Df Pr(>Chisq)    
Microsite        0.3906  1  0.5319716    
mn.gr.abun      18.6157  1  1.599e-05 ***
Size            14.1526  2  0.0008449 ***
ndvi            18.3934  1  1.797e-05 ***
mn.gr.abun:Size  6.2710  2  0.0434791 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
mseeds <- glmmTMB(percent ~Microsite + mn.gr.abun:Size + ndvi  + arid + (1|Site), seeds)
glmm.hp(mseeds)
$r.squaredGLMM
            R2m       R2c
[1,] 0.09339004 0.2850194

$hierarchical.partitioning
                 Unique Average.share Individual I.perc(%)
Microsite        0.0006       -0.0001     0.0005      0.54
mn.gr.abun:Size  0.0329       -0.0052     0.0277     29.66
ndvi             0.0595        0.0568     0.1163    124.52
arid            -0.1188        0.0677    -0.0511    -54.71

$variables
[1] "Microsite"       "mn.gr.abun:Size" "ndvi"            "arid"           

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
g1 <- glmm.hp(mseeds, commonality = TRUE)
plot(g1)

m11.1 <- glmmTMB(percent ~Microsite + mn.gr.abun*Size + ndvi  + gr.webers + (1|Site), seeds)
summary(m11.1)
 Family: gaussian  ( identity )
Formula:          percent ~ Microsite + mn.gr.abun * Size + ndvi + gr.webers +  
    (1 | Site)
Data: seeds

     AIC      BIC   logLik deviance df.resid 
  5793.7   5841.7  -2885.8   5771.7      571 

Random effects:

Conditional model:
 Groups   Name        Variance Std.Dev.
 Site     (Intercept)  476.8   21.84   
 Residual             1137.8   33.73   
Number of obs: 582, groups:  Site, 7

Dispersion estimate for gaussian family (sigma^2): 1.14e+03 

Conditional model:
                      Estimate Std. Error z value Pr(>|z|)    
(Intercept)          44.340351  19.158036   2.314  0.02064 *  
Micrositeshrub       -1.278338   2.803409  -0.456  0.64839    
mn.gr.abun            8.188801   2.337657   3.503  0.00046 ***
Sizemed               8.929615   4.616704   1.934  0.05309 .  
Sizesmall            18.744112   4.639385   4.040 5.34e-05 ***
ndvi                 -0.014442   0.003538  -4.082 4.47e-05 ***
gr.webers            12.801958  12.596040   1.016  0.30946    
mn.gr.abun:Sizemed   -1.711329   3.118946  -0.549  0.58322    
mn.gr.abun:Sizesmall -6.673657   2.986515  -2.235  0.02544 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
m11.2 <- glmmTMB(percent ~Microsite + mn.gr.abun:Size + arid  + gr.webers + (1|Site), seeds)
glmm.hp(m11.2)
$r.squaredGLMM
            R2m       R2c
[1,] 0.05091296 0.1675628

$hierarchical.partitioning
                 Unique Average.share Individual I.perc(%)
Microsite        0.0000        0.0002     0.0002      0.39
mn.gr.abun:Size -0.0106        0.0128     0.0022      4.31
arid             0.0064        0.0013     0.0077     15.10
gr.webers        0.0170        0.0239     0.0409     80.20

$variables
[1] "Microsite"       "mn.gr.abun:Size" "arid"            "gr.webers"      

$type
[1] "hierarchical.partitioning"

attr(,"class")
[1] "glmmhp"
AIC(m11.1, m11.2)
      df      AIC
m11.1 11 5793.699
m11.2  9 5825.594
BIC(m11.1, m11.2, m11.9)
Warning in BIC.default(m11.1, m11.2, m11.9): models are not all fitted to the
same number of observations
      df      BIC
m11.1 11 5841.730
m11.2  9 5864.892
m11.9  9 5955.815
em <-emtrends(m11.9, ~"Size", var= "mn.gr.abun")


pairs(em)
 contrast      estimate   SE  df t.ratio p.value
 large - med     -2.191 2.34 584  -0.936  0.6177
 large - small   -1.365 2.26 584  -0.605  0.8177
 med - small      0.827 2.35 584   0.351  0.9344

Results are averaged over the levels of: Microsite 
P value adjustment: tukey method for comparing a family of 3 estimates 
summary(em)
 Size  mn.gr.abun.trend   SE  df lower.CL upper.CL
 large             4.98 1.92 584     1.22     8.75
 med               7.18 2.05 584     3.14    11.21
 small             6.35 1.93 584     2.56    10.14

Results are averaged over the levels of: Microsite 
Confidence level used: 0.95 
test(em)
 Size  mn.gr.abun.trend   SE  df t.ratio p.value
 large             4.98 1.92 584   2.601  0.0095
 med               7.18 2.05 584   3.495  0.0005
 small             6.35 1.93 584   3.291  0.0011

Results are averaged over the levels of: Microsite 
plot(em)

ggplot(seeds, aes(mn.gr.abun, percent, fill = Size)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(seeds, aes(ndvi, percent)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(seeds, aes(arid, percent, fill = Size)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(seeds, aes(mn.abun.ants, gr.webers)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 11 rows containing non-finite outside the scale range
(`stat_smooth()`).

ggplot(seeds, aes(mn.abun.ants, percent)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(seeds, aes(mn.gr.abun, percent)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(seeds, aes(gr.webers, percent)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 11 rows containing non-finite outside the scale range
(`stat_smooth()`).

ggplot(seeds, aes(arid, percent)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(seeds, aes(ndvi, percent)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

ggplot(seeds, aes(arid, mn.abun.ants)) + geom_smooth(method = "lm")
`geom_smooth()` using formula = 'y ~ x'

Seed Removal Figures

library(gridExtra)

Attaching package: 'gridExtra'
The following object is masked from 'package:dplyr':

    combine
seeds$Size <- factor(seeds$Size, levels = c("small", "med", "large"))

a<-ggplot(seeds, aes(mn.abun.ants, percent))+ stat_smooth(data = filter(seeds, Size == "small"), aes(color = Size), method = "lm", linetype = "dashed", se = FALSE) +  stat_smooth(data = filter(seeds, Size == "med"), aes(color = Size),method = "lm") +  stat_smooth(data = filter(seeds, Size == "large"), aes(color = Size),method = "lm")   + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black"))+ xlab("Mean ant abundance") + ylab("Seeds removed (%)") + geom_point(alpha = 0.3, position = "jitter") + guides(color=guide_legend(title="Bait Size", position = "top"))


a
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'

b <- ggplot(seeds, aes(ndvi, percent)) + geom_smooth(method = "lm") + xlab("Productivity (NDVI)") + ylab("Seeds removed (%)") + geom_point(alpha = 0.3, position = "jitter") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black"))




plots <- list(a,b)
grobs <- list()
widths <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths[2:5]
}
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
maxwidth <- do.call(grid::unit.pmax, widths)
for (i in 1:length(grobs)){
     grobs[[i]]$widths[2:5] <- as.list(maxwidth)
}

p <- do.call("grid.arrange", c(grobs, ncol = 1))

p
TableGrob (2 x 1) "arrange": 2 grobs
  z     cells    name           grob
1 1 (1-1,1-1) arrange gtable[layout]
2 2 (2-2,1-1) arrange gtable[layout]

Ant Size Figure

a <- ggplot(pts, aes(Microsite, gr.webers)) + geom_boxplot() + xlab("Microsite") + ylab("Ant body size (mm)") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + stat_summary(fun = "mean", geom = "point", shape = 23, size = 4, fill = "red", color = "black")

b <- ggplot(pts, aes(arid, gr.webers)) + geom_smooth(method = "lm")  + xlab("DeMartonne's Aridity Index") + ylab("Ant body size (mm)") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + geom_point(position = "jitter", alpha = 0.5)
b
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 356 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 356 rows containing missing values or values outside the scale range
(`geom_point()`).

p <- plot(glmm.hp(m7), plot.perc = TRUE)
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
mod3 <- m7
plot(glmm.hp(mod3,type="R2"))
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

p <- glmm.hp(mod3,commonality=TRUE)
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; extreme or very small
eigenvalues detected. See vignette('troubleshooting')
Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')

Warning in fitTMB(TMBStruc): Model convergence problem; non-positive-definite
Hessian matrix. See vignette('troubleshooting')
p[["variables"]] <- c("CWM Seed Size", "Aridity", "Microsite")
plot(p, dig = 2)

c <- ggplot(plt.ag, aes(Microsite.x, nat.cwm)) + geom_boxplot() + xlab("Microsite") + ylab("Native Seed size") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + stat_summary(fun = "mean", geom = "point", shape = 23, size = 4, fill = "red", color = "black")


c
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_boxplot()`).
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_summary()`).

d <- ggplot(plt.ag, aes(arid, nat.cwm)) + geom_smooth(method = "lm")  + xlab("DeMartonne's Aridity Index") + ylab("Native Seed Size") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + geom_point(position = "jitter", alpha = 0.5)
d
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 286 rows containing missing values or values outside the scale range
(`geom_point()`).

e <- ggplot(plt.ag, aes(Microsite.x, cwm.inv)) + geom_boxplot() + xlab("Microsite") + ylab("Invasive Seed size") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + stat_summary(fun = "mean", geom = "point", shape = 23, size = 4, fill = "red", color = "black")

f <- ggplot(plt.ag, aes(arid, cwm.inv)) + geom_smooth(method = "lm")  + xlab("DeMartonne's Aridity Index") + ylab("Invasive Seed Size") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + geom_point(position = "jitter", alpha = 0.5)

f
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 208 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 208 rows containing missing values or values outside the scale range
(`geom_point()`).

plots <- list(a,c, e, b, d, f)
grobs <- list()
widths <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths[2:5]
}
Warning: Removed 356 rows containing non-finite outside the scale range
(`stat_boxplot()`).
Warning: Removed 356 rows containing non-finite outside the scale range
(`stat_summary()`).
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_boxplot()`).
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_summary()`).
Warning: Removed 208 rows containing non-finite outside the scale range
(`stat_boxplot()`).
Warning: Removed 208 rows containing non-finite outside the scale range
(`stat_summary()`).
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 356 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 356 rows containing missing values or values outside the scale range
(`geom_point()`).
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 286 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 286 rows containing missing values or values outside the scale range
(`geom_point()`).
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 208 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 208 rows containing missing values or values outside the scale range
(`geom_point()`).
maxwidth <- do.call(grid::unit.pmax, widths)
for (i in 1:length(grobs)){
     grobs[[i]]$widths[2:5] <- as.list(maxwidth)
}

p <- do.call("grid.arrange", c(grobs, ncol = 3))

p
TableGrob (2 x 3) "arrange": 6 grobs
  z     cells    name           grob
1 1 (1-1,1-1) arrange gtable[layout]
2 2 (1-1,2-2) arrange gtable[layout]
3 3 (1-1,3-3) arrange gtable[layout]
4 4 (2-2,1-1) arrange gtable[layout]
5 5 (2-2,2-2) arrange gtable[layout]
6 6 (2-2,3-3) arrange gtable[layout]
ggplot(pts, aes(cwm.site, gr.webers)) + geom_smooth(method = "lm") + geom_point()
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 356 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 356 rows containing missing values or values outside the scale range
(`geom_point()`).

Abundance and richness figures

# shrub needs to be a dashed line with no SE

a <- ggplot(plt.ag, aes(arid, abun, color = Microsite.x)) + stat_smooth(data = filter(plt.ag, Microsite.x == "open"), method = "lm") + stat_smooth(data = filter(plt.ag,, Microsite.x == "shrub"), method = "lm", linetype = "dashed", se = FALSE)+ xlab("DeMartonne's Aridity Index") + ylab("Annual Abundance \n per quadrat") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + guides(fill=guide_legend(title="Microsite")) + geom_point(position = "jitter", alpha = 0.5) + scale_color_manual(values = c( "#DF7861", "#94B49F")) + guides(color=guide_legend(title="Microsite", position = "top"))


a
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'

b <- ggplot(plt.ag, aes(arid, rich, color = Microsite.x)) + geom_smooth(method = "lm") + xlab("DeMartonne's Aridity Index") + ylab("Annual Species Richness \n per quadrat") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + guides(fill=guide_legend(title="Microsite")) + geom_point(position = "jitter", alpha = 0.5) + scale_color_manual(values = c("#DF7861", "#94B49F")) + guides(color=guide_legend(title="Microsite", position = "top"))

b
`geom_smooth()` using formula = 'y ~ x'

c <- ggplot(filter(pts, gr.abun < 75), aes(ndvi, gr.abun)) + geom_smooth(method = "lm") + xlab("Productivity (NDVI)") + ylab("Granivorous ant \n abundance per pitfall") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + geom_point(position = "jitter", alpha = 0.5)
c
`geom_smooth()` using formula = 'y ~ x'

d <- ggplot(pts, aes(ndvi, gr.richness)) + geom_smooth(method = "lm") + xlab("Productivity (NDVI)") + ylab("Granivorous ant \n richness per pitfall") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + geom_point(position = "jitter", alpha = 0.5)

d
`geom_smooth()` using formula = 'y ~ x'

plots <- list(a,c, b, d)
grobs <- list()
widths <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths[2:5]
}
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
maxwidth <- do.call(grid::unit.pmax, widths)
for (i in 1:length(grobs)){
     grobs[[i]]$widths[2:5] <- as.list(maxwidth)
}

p <- do.call("grid.arrange", c(grobs, ncol = 2))

p
TableGrob (2 x 2) "arrange": 4 grobs
  z     cells    name           grob
1 1 (1-1,1-1) arrange gtable[layout]
2 2 (1-1,2-2) arrange gtable[layout]
3 3 (2-2,1-1) arrange gtable[layout]
4 4 (2-2,2-2) arrange gtable[layout]
#ndvi for supplemental information

ggplot(plt.ag, aes(ndvi, abun, fill = Microsite.x)) + geom_smooth(method = "lm") + xlab("Productivity (NDVI)") + ylab("Annual Abundance \n per quadrat") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + guides(fill=guide_legend(title="Microsite"))
`geom_smooth()` using formula = 'y ~ x'

#arid for the ants

e <- ggplot(filter(pts, gr.abun < 75), aes(ndvi, gr.abun)) + geom_smooth(method = "lm") + xlab("DeMartonne's Aridity Index") + ylab("Granivorous ant \n abundance per pitfall") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + geom_point(position = "jitter", alpha = 0.5)

e
`geom_smooth()` using formula = 'y ~ x'

f <- ggplot(pts, aes(arid, gr.richness)) + geom_smooth(method = "lm") + xlab("DeMartonne's Aridity Index") + ylab("Granivorous ant \n richness per pitfall") + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), , panel.background = element_blank(), axis.line = element_line(colour = "black")) + geom_point(position = "jitter", alpha = 0.5)
f
`geom_smooth()` using formula = 'y ~ x'

plots <- list(e,f)
grobs <- list()
widths <- list()

for (i in 1:length(plots)){
    grobs[[i]] <- ggplotGrob(plots[[i]])
    widths[[i]] <- grobs[[i]]$widths[2:5]
}
`geom_smooth()` using formula = 'y ~ x'
`geom_smooth()` using formula = 'y ~ x'
maxwidth <- do.call(grid::unit.pmax, widths)
for (i in 1:length(grobs)){
     grobs[[i]]$widths[2:5] <- as.list(maxwidth)
}

p <- do.call("grid.arrange", c(grobs, ncol = 1))

p
TableGrob (2 x 1) "arrange": 2 grobs
  z     cells    name           grob
1 1 (1-1,1-1) arrange gtable[layout]
2 2 (2-2,1-1) arrange gtable[layout]