Say I have data of 500+ species at different locations .
I have my response Y and I want to find out how my continuous predictor humidity effects my Y. I ideally would control for the impact of species by using a linear mixed model LMM and using species as random effect. However 80% of my species have just 1 individual and a very few have 1000 or more, making this quite unbalanced. So using a LMM may not be a good idea?
I thought about weighting the species instead.
If I give a species with one individual the weight 1 , a species with two individuals the weight 1/2 and so on , so defining my weight as 1/n
, I would like to make sure that my model can incorporate the species information, so that my predictions are not influenced more by e.g., the top 10 species with individuals 100+ .Their Y values should not be equal to 100 other species with 1 individual in the regression.
how can I do this in R?
there is a weights argument in lm()
so I could do:
lm(Y ~ X, weights=1/n)
however the weight in lm()
is the weight of the uncertainty I have in my point or the variance, so I think I cannot use it this way.
What would be an appropriate method with robust estimates of standard errors for my coefficients.
I saw that there is the package library(survey)
with the function svyglm()
. Would specifying weights there as below be correct?
des <- svydesign(id=~1, weights= ~n, data=data)
svyglm(Y ~ X, des)
Or are there better options to achieve equal weighting of species .
(Note I think I cannot simply average over species because those are at different locations, so I would also need to average my predictor X then for those species)