对于带有poly项的混合模型,如何在DHARMa中模拟残差?

问题描述

我正在尝试使用DHARMa模拟包含正交多项式项的模型的残差:

cpr<-glmmTMB(cp ~ poly(zrc,2)*poly(zoc,2) + site + (1|plotpair),family = poisson,ziformula = ~0,data = onrom) 

cprsimulationOutput <- simulateResiduals(fittedModel = cpr,plot = T)

我收到以下错误消息:

Error in (function (...,degree = 1,coefs = NULL,raw = FALSE)  : 
  wrong number of columns in new data: c(-2.14030967312799,...)

如果我使用(I(zrc^2) + zrc)*(I(zoc^2) + zoc)使用原始多项式运行模型,则残差模拟运行得很好。这是不理想的,因为我想独立地评估每个多项式次数的重要性。

我在此thread中了解到,poly()函数在内部建立了一个新的模型矩阵,并为我的多项式预测变量的每个度数提供了单独的列。我怀疑这是在DHARMa中运行残差模拟时出现的错误的根源,尽管我不确定如何解决该问题。任何帮助将不胜感激。

我的数据:

>dput(onrom)

structure(list(tp = c(466,340,473,330,532,832,408,379,803,647,857,327,632,872,912,904,723,649,873,290,377,690,393,800,1347,370,540,923,375,630,1107,494,550,531,664,663,158,733,347,385,395,565,412,523,192,350,560,360,1170,6,324,162,390,403,421,460,943,621,570,978,470,602,764,335,1084,1011,331,279,274,917,777,740,485,357,444,747,439,382,468,465,275,1121,815,244,231,301,755,735,321,281,802,662,365,826,920,593,454,759,425,526,141,601,520,580,615,1007,562,410,419,828,1200,519,1157),cp = c(445,472,530,829,378,760,645,852,869,910,900,720,376,500,870,1100,490,660,730,411,190,381,415,940,620,600,1072,1010,270,250,911,773,480,435,746,354,1120,240,230,297,715,320,268,650,820,450,135,1000,515,hp = c(21,1,2,3,43,5,4,149,7,22,31,12,9,24,10,29,28,8,20,13,36,0),cpfrac = c(0.954935622317597,0.997885835095137,0.996240601503759,0.996394230769231,0.997361477572559,0.946450809464508,0.996908809891808,0.99416569428238,0.996559633027523,0.99780701754386,0.995575221238938,0.995850622406639,0.992084432717678,0.770416024653313,0.996563573883162,0.994694960212202,0.99236641221374,0.996749729144095,0.993676603432701,0.991902834008097,0.998116760828625,0.993975903614458,0.995907230559345,0.979827089337176,0.997572815533981,0.994263862332696,0.989583333333333,0.945409429280397,0.985748218527316,0.996818663838812,0.998389694041868,0.996677740863787,0.959424083769634,0.988929889298893,0.999010880316518,0.996978851963746,0.967741935483871,0.912408759124088,0.993456924754635,0.974025974025974,0.994851994851995,0.989690721649485,0.980392156862745,0.97972972972973,0.998661311914324,0.933940774487471,0.926701570680628,0.982905982905983,0.999107939339875,0.983606557377049,0.995670995670996,0.98671096345515,0.972789115646258,0.996884735202492,0.953736654804271,0.981873111782477,0.99273607748184,0.991189427312775,0.931558935361217,0.957446808510638,0.998336106489185,0.99304865938431,0.978520286396181,0.992292870905588,1),rcount = c(2,11,14,15,16,17,21,23,25,27,32,33,34,35,38,40,41,44,45,46,50,51,52,54,57,58,59,60,61,63,65,67,68,70,73,74,75,76,77,81,85,90,94,96,103,104,105,108,110,113,120,122,124,138,144,150,151,154,167,175,188,200,210,217,272,310),ocount = c(15,19,26,53,47,49,69,227,221,30,18,109,155,42,123,100,182,106,56,143,4),plotpair = structure(c(10L,18L,77L,5L,43L,50L,54L,73L,75L,41L,72L,82L,42L,1L,4L,7L,64L,80L,67L,14L,21L,45L,55L,63L,66L,31L,36L,78L,16L,3L,69L,79L,44L,28L,58L,17L,51L,48L,13L,62L,6L,39L,71L,49L,11L,24L,30L,56L,23L,52L,68L,37L,8L,65L,46L,74L,76L,25L,15L,38L,9L,34L,70L,35L,47L,59L,29L,26L,81L,33L,27L,2L,20L,12L,40L,60L,22L,61L,53L,57L,19L,32L,61L),.Label = c("100","101","102","103","104","105","108","109","110","12","14","15","17","18","19","20","21","22","24","25","26","29","31","32","33","35","36","37","39","40","41","42","43","45","46","47","48","49","50","51","52","53","55","56","58","59","60","61","62","63","64","65","66","67","68","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","88","90","91","92","93","94","95","96","98","99"),class = "factor"),obs = structure(c(1L,1L),.Label = c("J","M"),site = structure(c(2L,.Label = c("12","9"),date = structure(c(2L,4L),.Label = c("fri12","mon1","mon8","thur11?","thur4","tue2","wed3"),zrc = structure(c(-2.14030967312799,-2.14030967312799,-1.89379837534285,-1.70258935783945,-1.54636021503453,-1.41427035689765,-1.29984891724939,-1.1989220547262,-1.10863989974598,-1.02696975632877,-0.952410756941067,-0.883823126232355,-0.761201739437657,-0.705899459155932,-0.653950951991978,-0.60497259663274,-0.433020298235307,-0.358461298847605,-0.289873668138893,-0.226371440710729,-0.196302112045422,-0.0855821379269807,-0.0600014938985168,-0.03516242320732,-0.0110231385392785,0.0575644921694332,0.100417818320671,0.121066719597598,0.180185878964131,0.199019339015945,0.217447746856137,0.28743666640981,0.304075789954568,0.320397958460488,0.352138177361563,0.397647346048039,0.412295359795956,0.426697176749265,0.440860936210357,0.454794380406594,0.481999457030991,0.50836732016648,0.533947964194945,0.546457499324272,0.570941677511854,0.606404170042158,0.617906194252675,0.629255869287268,0.640457178303357,0.651513950262895,0.694367276414133,0.735179177090644,0.783603808399771,0.820464886790677,0.838317364551344,0.898025248048029,0.906225195194468,0.914347416553949,0.938262120448138,0.953842330350484,0.976694029595595,1.02775777887224,1.04180543672246,1.05562650954122,1.14659390081363,1.18280582164491,1.21185565234614,1.2175492808535,1.22320532738073,1.23995285600347,1.30896563578452,1.34882807604508,1.40989249830771,1.46264071429101,1.50424538748872,1.5322115785416,1.72499142680156,1.83666201998547),.Dim = c(125L,"`scaled:center`" = 3.59638309262833,"`scaled:scale`" = 1.16701374353451),zoc = structure(c(-0.151593506822675,-1.91438200437414,0.0375702074126911,0.118366750759085,0.863725927173292,0.291975495097031,0.996684752479822,-0.983064115933585,0.156049491141607,-0.550025958437796,1.4351745176674,0.352552836286872,0.879571660947518,-0.32761397988406,0.226733921648057,1.11158965814641,0.743645656992095,0.982900349993655,0.779724381617877,-0.852387181842082,-0.469229415091403,0.814330087498544,1.09956502994475,-0.395467950083098,2.10059796962715,-0.639342393343521,1.1692800811866,-0.151593506822675,0.705962916609572,2.42931537000042,2.0779907078869,1.37610531079192,0.409088586629335,-2.50197817022462,-0.100200676649585,0.72501365259282,0.511968864094258,-1.32678583852365,-0.739189672673162,0.322805149858892,-0.00591225051437896,1.48272279669543,1.77889624025747,0.462088473349149,0.686474194527964,-1.13762212428828,-1.57066028178407,-0.206304235847732,1.58428091833031,1.41036136846202,0.968888095853243,-0.0517462274930336,-0.264791015991595,0.19212821576739,1.0235988248783,1.91421823843421,1.45928198319233,0.559076653595864,0.259982185966427,0.535849938357454,0.925405637926173,1.71104227005843,-1.13762212428828),"`scaled:center`" = 2.95141325846398,"`scaled:scale`" = 1.17963189830669)),row.names = c(NA,-125L),class = c("tbl_df","tbl","data.frame"))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...