二项式线性混合模型R中的方差结构误差

时间:2017-02-07 21:50:50

标签: r glm lme4 mixed-models

我在线性混合效应模型中有一个二项式响应变量,残差图表明需要有一个基于一个分类变量(“fgear”)和一个连续变量(“mean”的值而变化的方差结构影响“)。查看标准化残差图: enter image description here

使用glmer包中的函数lme4开发完整模型。该模型有2个主要效果(无交互)和随机截距(“fgear”),指定为:

glmer(stayed ~ mean.impact + mean.landings + (1|fgear),
   family=binomial(link=cloglog), data = df)

我切换到使用glmmPQL包中的MASS来添加新的差异结构。我想使用varIdentvarExpvarConstPower函数运行方差结构,并使用AIC值或对数似然比较它们,但我得到以下错误:

glmmPQL(stayed~mean.impact+mean.landings, random=~1|fgear,family=binomial(link=cloglog), 
        data = df, weights = varIdent(form=~1|fgear))

## Error in model.frame.default(data = df, weights = varIdent(form = ~1 |  : 
   variable lengths differ (found for '(weights)')

glmmPQL(stayed~mean.impact+mean.landings, random=~1|fgear,family=binomial(link=cloglog), 
        data = df, weights = varExp(form=~mean.impact|fgear))

## Error in model.frame.default(data = df, weights = varExp(form = ~mean.impact |  : variable lengths differ (found for '(weights)')

glmmPQL(stayed~mean.impact+mean.landings, random=~1|fgear,family=binomial(link=cloglog), data = df, 
                            weights = varConstPower(form=~mean.impact))

## Error in model.frame.default(data = df, weights = varConstPower(form = ~mean.impact),  :  invalid type (list) for variable '(weights)'

glmmPQL(stayed~mean.impact+mean.landings, random=~1|fgear,family=binomial(link=cloglog), data = df, 
           weights = varConstPower(form=~mean.impact|fgear))

##  Error in model.frame.default(data = df, weights = varConstPower(form = ~mean.impact |  :  invalid type (list) for variable '(weights)'

我一直在使用Zuur等人的书。 “生态学中的混合效应模型和扩展与R”作为参考。提前感谢任何提示!这里可重复的数据:

> dput(df)
structure(list(fgear = structure(c(2L, 3L, 1L, 3L, 2L, 2L, 2L, 
3L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 1L, 2L, 2L, 2L, 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2L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 2L), .Label = c("Bottom Longline", "Bandit", 
"Handline"), class = "factor"), mean.impact = c(0.0748608431057302, 
0, 0.208104817907987, 0, 0, 0.0968181807548636, 0.0210189389008723, 
0.00249999994412, 0, 0, 0, 0, 0.207231937743483, 0, 0.516822755932599, 
0, 0.516271669432194, 0, 0.550270617155763, 0, 0.378786137328359, 
0.431426781663857, 0.00328358208565933, 0.126086954837391, 0, 
0.185438654213383, 0.0448834899641984, 0, 0.229999996722, 0.118834495589975, 
0.00234700964910176, 0.0206779646174024, 0.0450581321978019, 
0.1937499996275, 0.0411940289300597, 0, 0.00230769225611538, 
0, 0.384486896680076, 0, 0.000591132991714286, 0.0485049824748347, 
0.0028965516594, 0, 0.145727270158829, 0.00313854139780989, 0.00676057056182553, 
0.00286454287673763, 0.00000952380931093333, 0.00033423863677584, 
0.000453732657322428, 0.135192307357048, 0.00000823045249093004, 
0, 0.0650136904415864, 0, 0.000875487838677574, 0.0367343649572475, 
0, 0, 0, 0.0161982286844029, 0.028134778433863, 0, 0, 0, 0.00271967654053634, 
0, 0, 0.139999996871, 0, 0.366391898493507, 0.000183486234430826, 
0.0787846496360485, 0.000322750953298004, 0.222957716966151, 
0.130118543141223, 0.0178203059098923, 0.195253512932781, 0, 
0.00136636633582535, 0.00176923072968492, 0, 0, 0, 0.40055893439825, 
0, 0.456629449141479, 0.00166666662941333, 0.0036345193492175, 
0, 0, 0.0592440478996259, 0, 0, 0.162027557475721, 0.000643939379546061, 
0.00974137909260552, 0.0105081721730767, 0, 0.184494607244089, 
0.0165092291808925, 0.000118343194825385, 0.227152525755858, 
0, 0.0844444433848889, 0.0507336517668567, 0, 0.0283465575866851, 
0.172039045658414, 0.00773972604066297, 0, 0.0597146429352955, 
0, 0.00771251764379294, 0.00599472032900535, 0.0052303521866145, 
0.0220884684937713, 0.000267361105135056, 0, 0.000634250672198403, 
0.270000010729, 0.00116891793857959, 0, 0.0140688727226757, 0.349284554258409, 
0.380000002682, 0, 0.00758620672698483, 0.223195918434407, 0.210130315475261, 
0.195809645574848, 0.189999997616, 0, 0.000989890502491576, 0.425428234070025, 
0.419151056011706, 0, 0.00144368339022997, 0.000814814809145199, 
0.412510353178102, 0.335945562685222, 0.0194223107755214, 0.193609389165385, 
0, 0.0700914025227188, 0.00379853476282288, 0.186666667461333, 
0, 0, 0.355273517888608, 0.0005416666468, 0.106447534407068, 
0.161504234324097, 0, 0.446847592247065, 0.174199460695831, 0, 
0, 0, 0, 0.253549140776024, 0.0421748366204519, 0.321954415142972, 
0.4150000065565, 0, 0.050754702756426, 0, 0.0788888875395556, 
0, 0.0928671613295921, 0.0906608142839201, 0.101709975646793, 
0.382451176161789, 0, 0.210695830440933, 0, 0, 0.365222455495422, 
0.00113265923361984, 0, 0, 0.0000447027794418389, 0.00148618808325393, 
0, 0.0165909869378129, 0.0412352045559053, 0, 0.0426318824686613, 
0.365263156984947, 0.109843567311306, 0, 0, 0.418999997774933, 
0.248553109725586, 0, 0, 0.08741912441819, 0, 0, 0.000641957143074604, 
0, 0, 0, 0.539273916419292, 0.0225608335407722, 0.00823529393357177, 
0, 0.00999999977648, 0.00553571416198, 0, 0.45675162504189, 0, 
0, 0.342067152384589, 0.247492174134666, 0.0398126134044059, 
0.520796047073775, 0.00131654936720174, 0.362199998420192, 0, 
0, 0.0050066748729397, 0.270000010729, 0.270000010729, 0.270000010729, 
0.301212140371838, 0.0126288580385378, 0, 0, 0, 0.0696501722588436, 
0, 0, 0, 0, 0.153203784600011, 0, 0, 0, 0, 0, 0, 0.000836501902273627, 
0, 0.139152786218651, 0, 0.00546424611871018, 0, 0, 0, 0, 0, 
0, 0, 0.000140394085531862, 0, 0, 0, 0, 0, 0, 0.249696507554821, 
0, 0.218389602837463, 0.00456303258697684, 0, 0, 0.15174418440918, 
0, 0.157878616116078, 0, 0.00999999977648286, 0, 0, 0.000792452833562264, 
0, 0, 0, 0, 0.000675381248520436, 0.411250529380345, 0.136458331098333, 
0, 0, 0.05499999877075, 0, 0.000965571372421066, 0.0386766895539886, 
0, 0, 0, 0, 0, 0.00583333335816667, 0, 0, 0.000909090888771212, 
0, 0, 0.22379999274987, 0, 0.00297873290987703, 0, 0, 0.00722222206079111, 
0.227499991655125, 0, 0, 0, 0, 0, 0.16873074331896, 0, 0, 0, 
0.256134982328685, 0, 0, 0, 0.00326236256444231, 0, 0, 0, 0, 
0, 0, 0.00105263155541895, 0, 0, 0, 0.00999999977648333, 0, 0, 
0.146666663625175, 0, 0, 0, 0, 0.189999997616, 0, 0.4048749964687, 
0.409999996424, 0.301848110274429, 0.327666664123817, 0, 0, 0, 
0), mean.landings = c(6.217849273048, 5.6126765, 6.45896897916667, 
6.5805365, 5.57769125, 4.326698, 4.63908138333333, 6.3965095, 
4.2318765, 3.72592288888889, 6.67876068, 5.99946982103839, 4.7564738361556, 
3.38151, 5.14762487996032, 4.258079, 5.1096716547619, 3.56960166666667, 
5.91382177289377, 6.42588222023809, 6.40844169739011, 5.26900902738095, 
5.66454513333333, 5.0398065, 5.05814475, 6.61644100833333, 5.47953063333333, 
6.55861485579048, 5.2120175, 4.80250223412698, 6.68959451468531, 
7.22959205045752, 6.55052628097594, 5.27596033333333, 4.9211284, 
3.871778, 6.1792435, 5.63517535791246, 5.47520670490983, 6.534278, 
5.90917737205387, 7.56430819124183, 6.47717981428571, 1.74206266666667, 
6.10870307142857, 6.24353001666667, 4.80768559259259, 4.91185719029304, 
6.18056046878788, 5.5080169177591, 5.73110171729323, 0.2567759, 
5.64824566394545, 6.37305199619048, 6.19266008333333, 5.87717290539949, 
5.9988354702381, 6.4312124785918, 4.102126125, 6.154727, 7.66048821909091, 
6.75783823141026, 6.5258166302521, 6.077885, 6.1929904302924, 
7.42064669111111, 5.69901674654365, 4.75158392156863, 4.294626, 
4.746501, 5.95500397521368, 5.46922940196078, 4.78386989583333, 
6.576084855, 5.62011518897759, 6.14380574772727, 5.00186419106326, 
7.4779857765654, 5.79987513103318, 6.57527425, 5.45519644444444, 
7.53339125, 6.07046734386364, 5.10041569281829, 5.59162866666667, 
5.27152959710145, 2.4585935, 6.82856547455305, 6.56122557142857, 
6.28159775555556, 3.93203015, 3.345340625, 5.40157892592593, 
5.075285, 5.92927178690476, 5.95405981904762, 4.3703908375, 6.103866, 
7.01031859375, 5.40065485714286, 6.32892912175341, 6.35453674356725, 
5.60470273909982, 6.26239825416667, 5.4872714, 3.3369855, 8.115577375, 
6.04882228138528, 6.35684872666361, 6.46184867324675, 4.749017, 
4.48579724431818, 3.93927049338817, 5.51526027272727, 6.60201678320175, 
6.63096844832418, 6.92237931818182, 7.0055032331825, 6.05995675, 
6.00042577546296, 6.12114523500323, 5.22516231666667, 6.42643699660562, 
4.432007, 6.08747066315789, 7.14917393204365, 5.40833116666667, 
5.2774340125, 2.682793, 6.12506356766457, 6.77690302705882, 6.7163062979798, 
3.613885, 4.82636538252747, 6.25646289145326, 6.10978863104762, 
5.6694000668984, 6.95487405809524, 6.75376464236381, 6.05803740616247, 
4.39572481818182, 5.81967724615385, 5.6372687, 6.34888425968045, 
5.86815957142857, 6.07679314166667, 6.14825186458333, 4.15189733333333, 
3.2324265, 7.64380826585859, 7.06001072029412, 6.33960277322344, 
6.25220420615385, 5.33619647944444, 6.4367272973399, 7.10375068954545, 
6.44467885367965, 6.4890305, 6.24865991333333, 6.85597301571429, 
6.23705519298246, 4.37293814761905, 6.07603956428571, 6.64660706291498, 
4.145064, 5.7290103183584, 5.22462064976801, 2.616593, 5.54317075, 
4.1693825, 4.34994951666667, 6.21514480555556, 5.99238755, 5.04556612222222, 
5.10250494444444, 5.938152875, 6.519421, 5.241787, 6.54530865428571, 
6.45940580598291, 5.01925475, 4.60378447772786, 5.52617418333333, 
6.05090783797027, 5.60002546314103, 6.11026291865079, 6.38562099107143, 
5.0361795821114, 6.32333191378621, 4.87425266666667, 5.21703981048727, 
6.20514154427936, 5.3559545, 3.257378, 4.58135445, 6.35305335722222, 
5.09936702619048, 6.44022261111111, 6.08630825814076, 2.14315037932331, 
6.02212038988095, 2.348163, 4.92479121634615, 5.64635232521645, 
5.61404022222222, 6.5142005300905, 5.316435, 3.216212, 5.649954, 
4.02847908181818, 5.04546356875, 6.04371905666667, 2.538261, 
5.667807875, 6.06617425, 5.06163836666667, 3.95069073333333, 
5.17112474840194, 5.6840386302381, 4.4135534, 4.3133365, 6.06632349358974, 
6.09489152950409, 5.34568101057971, 5.25684845833333, 5.5706456, 
5.44872547142857, 6.25586029086965, 5.002026, 4.81635980434783, 
4.68215250793651, 6.04429078571877, 4.80671353571429, 5.52866956845238, 
6.16662685416667, 5.51797784615385, 5.80995548922334, 5.67800113611111, 
5.16235025396825, 5.4221181875, 4.841892875, 4.41284683333333, 
3.79501225, 6.66282425261438, 6.21331575, 5.20110129398148, 5.86412108, 
5.75800669416925, 4.94779941666667, 4.67115133333333, 4.896535375, 
4.20242725, 4.6870955, 4.7295375, 6.23570748235294, 5.1507922030101, 
4.77552231840659, 2.7974264, 5.37072516666667, 4.4734065, 5.16448475, 
5.6219035875, 4.90435632383297, 5.06161938888889, 4.64522929692308, 
6.91469903681457, 4.61899510310873, 6.60053102884615, 5.677876625, 
5.45592654806389, 6.64129666805556, 5.65846475992064, 3.979069, 
6.16885575641026, 5.81848311111111, 5.77814603392857, 5.50516844742047, 
3.73374333333333, 3.01777784757843, 2.493205, 6.32012005555556, 
5.97294201407867, 4.19543541666667, 5.29475852777778, 5.194587, 
4.836903125, 4.06879187777778, 4.9607182, 6.46664326857143, 4.1958228125, 
6.2010281, 5.37474458333333, 5.6854626, 6.645355499186, 3.78876447777778, 
5.4156705, 5.96848151442308, 6.18102625, 5.63583130113636, 3.228865421875, 
5.52942014047619, 5.93950680952381, 6.13939759888889, 5.0013755, 
4.43910716333333, 5.984462875, 4.915127625, 6.01677569, 4.29315395833333, 
4.429855625, 4.15683001785714, 5.967567303653, 4.99786602043697, 
2.64064985, 5.53474463888889, 5.05509745050204, 5.45728243568302, 
5.30879526831043, 3.78347913636364, 4.93901310833333, 5.8560928474026, 
5.15749933333333, 4.32284603039461, 5.1708304, 6.4818305996732, 
4.9938728965368, 5.04713818518518, 5.90084833333333, 4.56989807857143, 
5.10542055454545, 4.596129, 5.1786646, 6.72786067857143, 6.62512, 
4.0715602, 4.714661125, 3.9155264, 4.1932805, 3.69125585, 3.69679316666667, 
5.96021900288018, 5.05435439423077, 5.56922869345238, 5.79786990373737, 
4.3363125, 3.5196911, 6.214393, 6.11161559791667, 6.65742530892857
), stayed = c(1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 
1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 
1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 
0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 
0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 
1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 
1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 
0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 
1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1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