[R-sig-ME] adding a kinship matrix as a random covariate
Ben Bolker
bbolker at gmail.com
Mon Nov 11 22:45:31 CET 2013
On 13-11-11 03:02 PM, Federico Calboli wrote:
> [This email might, or might have not, bounced, so I'm sending it a
> second time. Apologies if you receive multiple copies]
>
> Hi All,
>
> I am possibly not up to date on using R mixed models when my random
> covariate is a Kinship matrix (from genetic data, not pedigree).
>
> I have a data frame (called my.data), with m rows and 126 columns.
> The columns are the phenotypes (quantitative) and a number of
> covariates, plus the genotype (coded as x/y, where y and y are
> microsatellite lengths). Independently I have a m by m matrix of
> kinship values, derived from the genetic data.
>
> All looks like:
>
>> my.data
>
> id temp bw bl dt rbw rbl sex MSA MSB MSC MSD
> MDE MSF MSG MSH 1 1 16 0.8707 16.66 54 0.01612407 0.3085185
> m 240/256 162/166 256/256 123/123 <NA> 120/156 331/335 115/115 2
> 2 16 0.8644 16.91 54 0.01600741 0.3131481 m 268/270 162/162
> 256/256 123/123 361/373 120/156 <NA> 115/119 3 3 16 0.8464
> 17.25 54 0.01567407 0.3194444 m 240/268 162/162 272/272 123/123
> 353/361 120/120 <NA> 115/115 4 4 16 0.9077 18.16 54 0.01680926
> 0.3362963 <NA> 256/270 162/162 <NA> 123/123 353/361 120/120
> <NA> 115/119 5 5 16 0.9075 18.05 53 0.01712264 0.3405660 f
> <NA> <NA> <NA> 111/115 353/361 120/120 <NA> 115/115 6 6
> 16 0.8296 17.36 53 0.01565283 0.3275472 f 268/270 162/162 <NA>
> 111/123 353/361 120/156 <NA> 115/119 7 7 16 0.8354 17.74 51
> 0.01638039 0.3478431 f <NA> <NA> <NA> 115/123 <NA>
> 120/156 <NA> 115/119 8 8 16 0.8614 16.84 53 0.01625283
> 0.3177358 f <NA> 162/162 256/256 123/123 <NA> 120/156
> <NA> 115/119 9 9 16 0.7756 18.22 54 0.01436296 0.3374074 f
> 268/270 <NA> 272/272 115/123 <NA> 120/120 <NA> 115/115 10 10
> 16 0.8076 16.37 53 0.01523774 0.3088679 f <NA> 162/172 <NA>
> 115/123 361/373 120/120 <NA> 115/115
>
> and the kinship matrix:
>
>> Kinship[1:6, 1:6]
> [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.5438596
> 0.4035088 0.3750000 0.3618421 0.3728070 0.3771930 [2,] 0.4035088
> 0.5614035 0.3903509 0.4298246 0.3925439 0.3925439 [3,] 0.3750000
> 0.3903509 0.5438596 0.3399123 0.3179825 0.3991228 [4,] 0.3618421
> 0.4298246 0.3399123 0.5219298 0.3771930 0.3662281 [5,] 0.3728070
> 0.3925439 0.3179825 0.3771930 0.5175439 0.3662281 [6,] 0.3771930
> 0.3925439 0.3991228 0.3662281 0.3662281 0.5833333
>
> I tried in lme4 the following:
>
> lmer(all$bw ~ all$MSA + all$temp + all$sex + all$dt + (1|Kinship))
>
> returns
>
> Error in `[[<-.data.frame`(`*tmp*`, i, value = c(233L, 174L, 161L,
> 162L, : replacement has 384120 rows, data has 485
>
>
> I tried in nlme this:
>
> lme(all$bw ~ all$MSA + all$temp + all$sex + all$dt, random = ~
> 1|Kinship, na.action = na.omit) Error in eval(expr, envir, enclos) :
> object 'bw' not found
>
> If I put the kinship in my.data
>
>> my.data$K = Kinship
>
> lme(bw ~ MSA + temp + sex + dt, random = ~ 1|K, data = my.data,
> na.action = na.omit) Error in `row.names<-.data.frame`(`*tmp*`,
> value = origOrder) : invalid 'row.names' length
>
> Obviously using a m by m matrix is not a good way of specifying a
> random effect. Given my data, which is not going to change, is there
> a way of using the K matrix as a random covariate? alternatively,
> which packages would allow me to do so? Finally, I will admit it
> openly, from the start. I am after a p-value, ideally from an anova,
> to see if the different genotypes at each locus have an effect or
> not.
>
Are any of these StackOverflow answers relevant/useful?
http://stackoverflow.com/questions/8245132/single-level-variables-in-mixed-model-lme4-error-in-r/8247412#8247412
http://stackoverflow.com/questions/19327088/reproducing-results-from-previous-answer-is-not-working-due-to-using-new-version/19382162#19382162
http://stackoverflow.com/questions/19104475/how-to-modify-slots-lme4-1-0/19106863#19106863
I would also look at the results of library("sos"); findFn("kinship") ,
although there's a fair amount to sort through there ... Perhaps in
conjunction with the reverse depends/reverse suggests of nlme and lme4 ... ?
More information about the R-sig-mixed-models
mailing list