如何使用glmer()解释GLMM泊松回归中的不同采样努力-easy Reproducted exampled inc
我一直在努力处理我的数据集,似乎已经有很长一段时间了。希望有人能给我指出正确的方向 我想知道如何使用glmer()解释我的GLMM泊松回归中不同的采样努力 我们从绘图中收集计数数据,有时3晚,有时2晚 我不确定我是否应该:如何使用glmer()解释GLMM泊松回归中的不同采样努力-easy Reproducted exampled inc,r,csv,offset,lme4,poisson,R,Csv,Offset,Lme4,Poisson,我一直在努力处理我的数据集,似乎已经有很长一段时间了。希望有人能给我指出正确的方向 我想知道如何使用glmer()解释我的GLMM泊松回归中不同的采样努力 我们从绘图中收集计数数据,有时3晚,有时2晚 我不确定我是否应该: 创建每个图的平均丰度,四舍五入平均值(泊松数的整数),然后运行我的模型-这消除了在我的完整数据集中发现的过度分散 添加采样工作量的偏移量(二进制2或3)- 偏移量(对数(采样工作量)) 添加位置(1 | Loc/Plot)和日期(1 | Date)内嵌套的绘图的随机效果,并希
# obtain data
dl_from_dropbox <- function(x, key) {
require(RCurl)
bin <- getBinaryURL(paste0("https://dl.dropboxusercontent.com/s/", key, "/", x),
ssl.verifypeer = FALSE)
con <- file(x, open = "wb")
writeBin(bin, con)
close(con)
message(noquote(paste(x, "read into", getwd())))
}
dl_from_dropbox("Reproducible_example.csv", "4z97tlkfedmutqr")
shell.exec("Reproducible_example.csv")
# read data
data<-read.csv("Reproducible_example.csv")
# run models
library(lme4)
glmer_offset_no_date<- glmer(Total_abundance ~ Habitat + (1|Loc/Plot) + offset(log(Sampling_effort)), data = data, family = poisson(link = "log"))
glmer_no_offset_no_date<- glmer(Total_abundance ~ Habitat + (1|Loc/Plot) , data = data, family = poisson(link = "log"))
glmer_offset_date<- glmer(Total_abundance ~ Habitat + (1|Loc/Plot) + (1|Date) + offset(log(Sampling_effort)), data = data, family = poisson(link = "log"))
glmer_no_offset_date<- glmer(Total_abundance ~ Habitat + (1|Loc/Plot) + (1|Date), data = data, family = poisson(link = "log"))
AIC(glmer_no_offset,glmer_offset,glmer_no_offset_date,glmer_offset_date)
# or take mean abundance per plot and run the model with/without an offset #
# tidy data
library(plyr)
Mean_abundance_per_plot<-ddply(data, c("Plot", "Loc", "Habitat", "latitude", "longitude"), colwise(mean))
Mean_abundance_per_plot<-Mean_abundance_per_plot[,-6]
library(dplyr)
Mean_abundance_per_plot_rounded<-Mean_abundance_per_plot %>% mutate_each(funs(round(.,0)), -c(Loc, Plot, Habitat,latitude, longitude))
# run models
glmer_avg_offset<- glmer(Total_abundance ~ Habitat + (1|Loc/Plot) + offset(log(Sampling_effort)), data = Mean_abundance_per_plot_rounded, family = poisson(link = "log"))
glmer_avg_no_offset<- glmer(Total_abundance ~ Habitat + (1|Loc/Plot), data = Mean_abundance_per_plot_rounded, family = poisson(link = "log")) # fails to converge
#获取数据
来自dropbox的dl_