0

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"
))
  • 1
    The first error is due to the `1 <-` being invalid and not due to the `glmer` code. Try `m1 <- ` – user20650 Apr 23 '23 at 13:56
  • 1
    Hi. Could you update your question to show which library `ecospat.Cscore` comes from please. – user20650 Apr 23 '23 at 13:58
  • FWIW, looks like it's the `ecospat` package ... – Ben Bolker Apr 23 '23 at 15:01
  • 1
    We don't know what "run a mixed model on the C.score of my data" means. From the documentation, a C-score is a summary of the joint presence-absence pairs for the community, or for a pair of species. What do you want to find out by running a mixed model? – Ben Bolker Apr 23 '23 at 15:20
  • @BenBolker I have edited the question to hopefully answer your questions. @user20650 it is the `ecospat` package – Marnee Roundtree Apr 23 '23 at 15:54
  • It's still not clear what you want to find out from the C scores. The C scores apply to *pairs* of species; your data (Data 1) appear to be at the level of observations on *individual* species. I don't understand what relationship you would be estimating, with what kind of data (i.e., how would you transform your data into a form useful for predicting *associations* of species ... ?) This might be better for [CrossValidated](https://stats.stackexchange.com) ... – Ben Bolker Apr 25 '23 at 20:07

0 Answers0