我有一些SAS代码运行三个不同的GLMM,我需要在R中运行相同的。任何人都可以帮我翻译吗?我之前从未与SAS合作过。我一直在使用' glmer.nb'来自lme4,但我愿意在必要时改变。 SAS代码如下。
libname dataset 'H:\ReefSAS';
PROC IMPORT DATAFILE = "H:\ReefSAS\reefdatasas.xls"
OUT = reefdata DBMS = xls REPLACE;
GETNAMES = yes;
RUN;
/*] "date" "reefID" "station" "densClass"
"easting" "northing" "altitude" "density" */
/* three different spatial structures */
proc mixed data=reefdata;
class date station densClass;
model density =station densClass;
Random reefID;
repeated date/ TYPE=SP(EXPGA)(easting northing) subject=reefID;
run;
proc mixed data=reefdata;
class date station densClass;
model density =station densClass;
Random reefID;
repeated date/ TYPE=SP(GAUGA)(easting northing) subject=reefID;
run;
proc mixed data=reefdata;
class date station densClass;
model density =station densClass;
Random reefID;
repeated date/ TYPE=SP(SPHGA)(easting northing) subject=reefID;
run;
编辑:我当前的代码有三个选项,一个工作(lme :: nlme),两个不工作(glmer.nb :: lme4和nlme :: nlme)。说实话,我不确定我是否正确地翻译了SAS的陈述。我还想指出,此刻的配方是线性的,但我的想法是,一旦我开始运行,就以非线性方式用其他变量的组合来建立固定效果。我到目前为止的代码:
library(lme4) # works, but it does not account for spatial auto-correlation
glmer.nb(density~date+densClass+1|reefID, data=reefdata)
library(nlme) # does not run, error below
nlme(model=density~alpha*date + beta*densClass, data=reefdata,
fixed=alpha+beta~date*densClass,
random=density~1|reefID,
start=list(fixed=0.05, alpha=0.05, beta=0.05),
correlation=corExp(form=~easting+northing |reefID))
# Error in nlme.formula(model = densAVG ~ alpha * dateLvls + beta * densClass, : starting values for the 'fixed' component are not the correct length
library(nlme) # works but does not incorporate spatial auto-correlation
lme(density~date+densClass, random=~1|reefID, data=reefdata)