An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20131101/905b668c/attachment.pl>
Manipulating matrices from MCMCglmm
3 messages · Jarrod Hadfield, Adam Hayward
Hi Adam,
Try this:
beta<-function(x, dimension=4, response=1){
V<-matrix(x,dimension, dimension)
solve(V[-response,-response],V[-response,response])
}
post.beta<-apply(m1$VCV[,1:16] 1, beta)
# you have to change 1:16 to the appropriate indices.
This has also been done in: Phillimore, A. B., S. St?lhandske, R. J.
Smithers, and R. Bernard. 2012. Dissecting the contributions of
plasticity and local adaptation to the phenology of a butterfly and
its host plants. American Naturalist 180: 655-670
Cheers,
Jarrod
Quoting Adam Hayward <a.hayward at sheffield.ac.uk> on Fri, 1 Nov 2013
15:47:02 +0000:
Hi all, I'mm running a 4-trait model in MCMCglmm in order to estimate selection on three traits (the first trait being lifetime reproductive success). The model gives me 1000 estimates of each of the variance components. I'm primarily interested in the first 16 components, which make up the 4x4 individual-level VCV matrix, but there are other variance components, some of which are not fitted to all traits. model$VCV spits this out as an object with dimensions of 1000xN, where N is the number of VCV components. Primarily, I would like to convert this into the thousand estimates of my 4x4 individual-level matrix, which I should then be able to use to calculate selection gradients accounting for correlated selection and have some measure of error around these estimates. For example, on a single estimate of a 4x4 VCV matrix: # matrix of VCV estimates
I<-as.matrix(cbind(
+ c(1, 1, 0.1, 0.5), + c(1, 1, 0.1, 0.1), + c(0.1, 0.1, 1, 0.1), + c(0.5, 0.1, 0.1, 1))) # get matrix, minus the trait we're estimating selection through, i.e. LRS
Ipred<-I[2:4,2:4] Ipred
[,1] [,2] [,3] [1,] 1.0 0.1 0.1 [2,] 0.1 1.0 0.1 [3,] 0.1 0.1 1.0 # get a vector of covariances between predictors and fitness
COV<-(I[1,])[2:4]
# calculate selection gradients
Beta<-ginv(Ipred)%*%COV Beta
[,1] [1,] -0.03703704 [2,] 0.40740741 [3,] 0.96296296 An added complication is that two of these "traits" are random slopes, but that will probably have to wait. I think for now my question is a *relatively* straightforward one- how would I go about obtaining my 1000 4x4 matrices to plug into the above formulas in order to get selection coefficients with some measure of error? I'd be very grateful if anyone has any advice. Best wishes, Adam -- Adam Hayward Post-Doctoral Research Associate Department of Animal and Plant Sciences Alfred Denny Building University of Sheffield Western Bank Sheffield S10 2TN UK http://www.huli.group.shef.ac.uk/adam-personal.html http://adhayward.wordpress.com/ https://twitter.com/adhayward18 [[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20131101/df963441/attachment.pl>