I was reviewing Building General Linear Mixed Model in R and Multivariate Linear Mixed Model in lme4 but have run into a different issue.
I have a two datasets containing the same species, etc information but one is set up to create a matrix and one is a data frame with an additional binary variable of assoc
. I want to see if the variables Species
, season
, cover
, or evi
, have a significant effect on the probability of associating assoc
. Additionally, I want to see if those same variables have a significant effect on the inter-species C.score
or the measure of co-occurrence between a species pair.
Data 1
assoc Species Transect year season cover evi
<fctr> <fctr> <fctr> <dbl> <chr> <chr> <chr>
1 FALSE RC C3 2 dry Deciduous edge
2 FALSE BW C3 2 dry Evergreen edge
3 TRUE RC C3 2 dry Evergreen interior
4 TRUE BW C3 2 dry Evergreen interior
5 FALSE SKS C3 2 dry Semi-Deciduous edge
6 FALSE SKS C3 2 dry Semi-Deciduous edge
7 FALSE RC C3 2 dry Open edge
8 FALSE BW Msolwa 2 dry Evergreen edge
9 FALSE RC Msolwa 2 dry Evergreen edge
10 FALSE RC Msolwa 2 dry Evergreen interior
Data 2
group_id RC BW SKS BABO MANG
<chr> <dbl><dbl><dbl><dbl><dbl>
2-1-15-Deciduous.dry_470 1 0 0 0 0
2-1-15-Evergreen.dry_1850 0 1 0 0 0
2-1-15-Evergreen.dry_2020 1 1 0 0 0
2-1-23-Semi-Deciduous.dry_1000 0 0 1 0 0
2-1-23-Semi-Deciduous.dry_1310 0 0 1 0 0
2-1-23-Open.dry_1745 1 0 0 0 0
2-1-25-Evergreen.dry_1805 1 1 0 0 0
2-1-25-Evergreen.dry_2050 1 0 0 0 0
2-1-29-Mixed.dry_750 1 0 0 0 0
2-1-29-Evergreen.dry_1958 1 0 0 0 0
1 <- glmer(assoc ~ (Species + cover + evi + season + (1|Transect) + (1|year)), data = data1, family = "binomial")
but get error
invalid (do_set) left-hand side to assignment
I also want to run a mixed model on the C.score of my data
To get C.score from data2
nperm <- 1000
outpath <- getwd()
Cscore <- ecospat.Cscore(data2, nperm, outpath, verbose = T)
I don't know where to go from here so any advice is greatly appreciated.
Dput
data1 <- structure(list(assoc = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L), levels = c("FALSE", "TRUE"), class = "factor"),
Species = structure(c(4L, 2L, 4L, 2L, 5L, 5L, 4L, 2L, 4L,
4L), levels = c("BABO", "BW", "MANG", "RC", "SKS"), class = "factor"),
Transect = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L), levels = c("C3", "Msolwa", "Mwani", "Sanje"), class = "factor"),
year = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), season = c("dry",
"dry", "dry", "dry", "dry", "dry", "dry", "dry", "dry", "dry"
), cover = c("Deciduous", "Evergreen", "Evergreen", "Evergreen",
"Semi-Deciduous", "Semi-Deciduous", "Open", "Evergreen",
"Evergreen", "Evergreen"), evi = c("edge", "edge", "interior",
"interior", "edge", "edge", "edge", "edge", "edge", "interior"
)), row.names = c(NA, 10L), class = "data.frame")
data2 <- structure(list(group_id = c("2-1-15-Deciduous.dry_470", "2-1-15-Evergreen.dry_1850",
"2-1-15-Evergreen.dry_2020", "2-1-23-Semi-Deciduous.dry_1000",
"2-1-23-Semi-Deciduous.dry_1310", "2-1-23-Open.dry_1745", "2-1-25-Evergreen.dry_1805",
"2-1-25-Evergreen.dry_2050", "2-1-29-Mixed.dry_750", "2-1-29-Evergreen.dry_1958"
), RC = c(1, 0, 1, 0, 0, 1, 1, 1, 1, 1), BW = c(0, 1, 1, 0, 0,
0, 1, 0, 0, 0), SKS = c(0, 0, 0, 1, 1, 0, 0, 0, 0, 0), BABO = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), MANG = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 0)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"
))