使用 brms 进行结构方程建模中的自相关项

问题描述 投票:0回答:1

我们正在尝试在 R 包“brms”中建立具有空间自相关的结构方程模型。当我将其用于线性模型时,它效果非常好: NPP.model =bf(NPP~climate1+海拔+地形+sar(plot.nb,type ="lag")) NPP.lm=brm(NPP.model,data=myco.res,data2=list(plot.nb=plot.nb),种子=13,iter=15000,核心=3,链=3,控制=列表(adapt_delta =0.98))

但是,当我们在结构方程模型中使用它时,它遇到了问题: NPP.model =bf(NPP~climate1+多样性+海拔+地形+sar(plot.nb,type ="lag")) 多样性.model=bf(多样性~气候1+海拔+地形+sar(plot.nb,type ="lag")) NPP.lm=brm(NPP.model+diversity.model++set_rescor(FALSE),data=myco.res,data2=list(plot.nb=plot.nb),seed =13,iter =15000,cores=3 ,链=3,控制=列表(adapt_delta=0.98))

程序有问题: 编译斯坦程序... stanc 中的错误(文件 = 文件,模型代码 = 模型代码,模型名称 = 模型名称,: 0 “string”中的语义错误,第 86 行,第 39 列到第 58 列:


84:    vector[Kc_NPP] b_NPP;  // regression coefficients
85:    real Intercept_NPP;  // temporary intercept for centered predictors
86:    real<lower=min_eigenMsarNPP,upper=max_eigenMsarNPP> errorsar_NPP;  // error-SAR correlation parameter
                                            ^
87:    real<lower=0> sigma_NPP;  // dispersion parameter
88:    vector[Kc_diversity] b_diversity;  // regression coefficients

标识符“max_eigenMsarNPP”不在范围内。您的意思是“max_eigenMsar_NPP”吗?

请帮助我们解决这个问题。

r compilation stan brms sem
1个回答
0
投票

感谢您的快速回复。请参阅以下代码作为示例: 库(spdep) 图书馆(brms)

#reading data
plot.data=read.csv("sar.data.csv");

#set neighboring weights
plot.coord=data.frame(x=plot.data$x,y=plot.data$y);
coordinates(plot.coord)=c("x","y")
plot.nb=tri2nb(plot.coord)

mod.NPP=bf(log(NPP)~richness+convex+sar(plot.nb,type="lag"))
mod.richness=bf(richness~convex+sar(plot.nb,type="lag"))
sem_brms_NPP=brm(mod.NPP+mod.richness+set_rescor(FALSE), data=plot.data,             seed=13,iter=15000,cores=3,chains=3,data2=list(plot.nb=plot.nb),control=list(adapt_delta=0.98))

Here are the data of the example:
x   y   NPP richness    convex
25  25  2.8568483   1.645074569 0.551449376
25  75  3.684366858 1.251241256 -1.337039999
25  125 3.812329981 0.069741316 -0.378752143
25  175 3.684699962 0.069741316 -0.272764288
25  225 3.509855693 0.660491286 -0.932703142
25  275 2.513996864 1.448157912 -0.987947194
25  325 2.74408847  1.841991226 -1.056747372
25  375 3.086323335 -0.521008654    -0.05671217
75  25  3.021667807 0.857407942 -0.947907831
75  75  3.505487797 1.645074569 -1.603287099
75  125 3.623973839 0.660491286 -1.586534176
75  175 5.670239667 -0.324091997    -0.964366237
75  225 3.420870045 -1.308675281    -0.765198026
75  275 8.268396407 -0.324091997    -0.159296043
75  325 4.128392893 -0.127175341    0.153874742
75  375 5.269113443 0.266657973 0.531723429
125 25  4.827352586 -0.914841967    1.404480423
125 75  5.268117927 -1.308675281    0.751703044
125 125 3.246826461 -0.127175341    0.591023624
125 175 4.586711654 -0.914841967    0.953414278
125 225 5.193110239 -1.702508594    0.806861658
125 275 4.240922052 -0.717925311    0.876459776
125 325 5.349005287 -1.111758624    1.142539619
125 375 5.79756553  -2.293258564    1.054840332
175 25  2.959063217 1.251241256 -1.663552086
175 75  5.153407404 -0.717925311    -0.011391671
175 125 5.361819719 -0.717925311    1.518184632
175 175 3.854002855 -1.111758624    0.532527229
175 225 2.694341396 0.463574629 -0.616505954
175 275 3.116381287 -0.127175341    0.152850644
175 325 3.096591984 0.069741316 0.410093912
175 375 4.005730227 -0.521008654    -0.803968288
225 25  4.878031569 1.645074569 0.000571537
225 75  3.775624482 1.054324599 -1.896424687
225 125 5.294353953 -0.324091997    -0.605502025
225 175 4.170131345 1.645074569 -0.824918419
225 225 7.402201938 -0.717925311    -0.914107682
225 275 7.096840757 -0.717925311    0.634250503
225 325 5.74439573  0.857407942 0.52751286
225 375 5.499097105 -0.717925311    2.308275987
275 25  6.220425675 0.266657973 1.59767398
275 75  2.400888897 1.251241256 -1.838173159
275 125 3.151753202 0.857407942 -2.021730195
275 175 5.106932843 1.054324599 -1.16256155
275 225 6.245960869 0.463574629 -0.838709922
275 275 5.682026301 -0.324091997    0.450291841
275 325 6.073772029 -0.521008654    0.847852698
275 375 3.697971779 0.266657973 -0.612746778
325 25  5.584248255 -1.702508594    2.293159011
325 75  5.874086696 1.054324599 0.097973551
325 125 4.930650129 -0.127175341    -0.756119465
325 175 4.605712213 0.857407942 -0.535799465
325 225 4.314188238 1.054324599 -1.368537483
325 275 4.042674268 0.857407942 -1.087210637
325 325 7.697667826 0.463574629 -0.344297714
325 375 5.45130729  -1.505591937    0.236676688
375 25  5.23767512  -0.717925311    -1.165736981
375 75  5.442370489 -1.702508594    1.734883277
375 125 4.153752117 -0.521008654    0.3688539
375 175 6.374074782 -0.521008654    0.537166354
375 225 4.361307428 0.463574629 0.748832645
375 275 4.600662313 1.251241256 -0.192271925
375 325 5.080090968 0.266657973 -0.063292719
375 375 2.909932186 -1.111758624    -1.278466557
425 25  4.692823205 -1.111758624    1.289452769
425 75  6.153898227 -0.717925311    1.081077307
425 125 4.948797315 -0.521008654    0.823857118
425 175 6.372011398 -0.914841967    0.83894609
425 225 8.226823544 -0.324091997    0.767451459
425 275 6.222034842 0.463574629 0.737614124
425 325 4.311067676 -1.505591937    1.042908587
425 375 4.263529094 -1.899425251    1.49031374
475 25  3.826527987 0.660491286 0.157430715
475 75  4.919966251 0.266657973 -0.500063723
475 125 4.09028079  -1.308675281    0.297725268
475 175 4.179978887 -0.324091997    0.121092474
475 225 5.524244786 -0.324091997    -0.408000105
475 275 5.674296718 0.463574629 0.946985094
475 325 3.954364867 0.660491286 0.520687853
475 375 4.14473555  -0.914841967    -0.43683558
525 25  3.634319813 0.266657973 1.667616148
525 75  3.428459518 -1.308675281    0.436487489
525 125 5.232819421 -0.914841967    -0.117766758
525 175 3.20637336  0.463574629 -0.101015395
525 225 5.627480433 0.069741316 0.163543884
525 275 4.498335733 -0.717925311    1.000020217
525 325 3.242990092 2.235824539 0.137041247
525 375 4.707353169 -1.308675281    0.751381917
575 25  3.861840468 2.038907882 0.686154178
575 75  2.557074157 0.857407942 -0.90534462
575 125 4.12845393  0.266657973 -0.12855679
575 175 4.266981397 0.266657973 0.818059117
575 225 4.369247136 0.660491286 -0.141970395
575 275 3.192727925 1.448157912 -1.464466616
575 325 2.999182439 0.266657973 -1.592244015
575 375 4.063909442 1.054324599 -2.144303272
© www.soinside.com 2019 - 2024. All rights reserved.