Replies: 6 comments 12 replies
-
See my answer of this morning in #157 . In short: yes, you need to do it manually, but I provide some code there that you can adjust to help you do it. |
Beta Was this translation helpful? Give feedback.
-
Oh, can this be made a vignette? Posthocs and comparisons for individual species are still something that I struggle with - and struggle with teaching! Would be very useful! |
Beta Was this translation helpful? Give feedback.
-
That would be amazing! Note, I've signed up for the seminar and am urging folk I know to do so. VERY excited. |
Beta Was this translation helpful? Give feedback.
-
@jebyrnes this got me thinking. So I have something for you. It is only a start, and I don't have much time to improve it at present, so please don't get too excited! But I know you have been waiting for it for some time.
Note to self: ordering of the SEs is a bit tricky, since the order of emmeans doesn't quite correspond with the order of the asymptotic covariance matrix in gllvm, so that needs to be kept an eye on. This also works for models with reduced rank terms, but at present this requires installing the package from the development repo. |
Beta Was this translation helpful? Give feedback.
-
Here is my small contribution. I have this model: Location is a categorical covariate with 8 levels (sorry...can't help). SpecData contains 16 morphometric variables. 240-ish rows (bees). The output from gllvm gives the estimated intercepts: And the slopes...which are corrections of the intercept in this specific example. You can plot them with: Or you can grab them from: So far so good. I then wanted to calculate the intercept + the correction of the intercept for each of the 8 locations...and for each morphometric variable. Hence...in this model: mu_ij = exp(Intercept + Location *beta_j + row-specific random effect + LV * theta_j) I want the combined effect of: Intercept + Location *beta_j I think it would be quite tricky to write code that can do this in any scenario (that is...add more covariates etc). So..I set myself on a mission to write an exercise that explains this step-by-step. And once you understand how that works, you can easily adjust it for your own data sets (instead of relying on emmeans and friends). So..in a univariate lm, it simplifies to: Bees2$fLocation <- factor(Bees2$Location) And then you get things like this: summary(Ma)$coefficients The intercept is the fitted value for location 1. But that does not give you SEs. So..we need a little trick. First, we need these two things: The estimated betas and their covariance matrix. Instead of calculating 9.18853333 + 0.18266667 by hand, I will do it via matrix multiplication. Define C as follows Multiply this matrix with the estimates betas: So that is the intercept plus the correction of the intercept for location 2. The fitted value for Location 2. Now work towards the SE. There is this stats rule: In other words, to get the SE of 'Intercept + fLocation2, we need: var(Intercept) + var(fLocation2) + 2 * cov(Intercept, fLocation2) where: #' We can also do it a little bit more sophisticated, and use #' Utilising this, we get: In other words, to get the fitted value for Location 2 and its SE, we need to define the C as: And then it is two lines of code: This gives you the 'Intercept + fLocation2' value and also its standard error. What remains is to do this for: But that is just a matter of changing the C 6 more times. And this is all for a linear regression model. #' What did we learn? Now..the good news is...in GLLVM it is a monkey-see-monkey copy. Here are all the parameters in the model: And the covariance matrix: Now we need to do exactly the same thing...but then 16 times. And you get a headache which values of Betas to add up. This is me doing it in a loop (j is for the 16 morphometric variables). #' And now for all morphometric variables. #' Pre-create C outside the loop and modify it in the loop #' Iterate over morphometric variables j.
} This is really the same thing as 16 times what I did for the univariate lm. And the standard errors: #' Pre-create C outside the loop and modify it in the loop #' Iterate over morphometric variables j.
} I'm sure that it can be done more efficiently. The end result is this graph: ![]() This shows the 'Intercept + Location" effect for each morphometric variable. Keep in mind that there are other terms in the model, and there is also a link function. For this specific example, the 'Intercept + Location' should probably be the same as predict(.., type = "link", and without the random stuff). Post-hoc tests In a univariate case, you would do this: #' And you can plot the results. All what that is doing is defining your C matrix like this: This is testing whether Location 7 is different from 8. #' Calculate the C x B: #' Calculate the standard error of Diff: It gives exactly the same value as glht. Then all that is needed is to do this for every combi of locations. And correcting for multiple tests. And this translates directly to GLLVM. But because of the 16 morphometric variables, the number of tests is quite large. And this is where I am right now. So..my weekend plan is to trim some trees and extend this to the GLLVM code. I hope this helps the original question from @jebyrnes ? And hopefully, this is actually correct...:-). Alain |
Beta Was this translation helpful? Give feedback.
-
I'm preparing an exercise in which I model 16 morphometric variables using GLLVM with a Gamma distribution...honeybee data. With one categorical covariate "Location" with 8 levels, a row-specific random effect, and 2 latent variables. All very nice....works perfectly.
I can see the following question coming: Can we test which locations differ from each other? So..that is post-hoc testing territory.
I guess you have to do that manually?
Alain
Beta Was this translation helpful? Give feedback.
All reactions