-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop a single coefficient (one level from categorical variable) from formula/modelmatrix for Likelihood ratio test #745
Comments
P.S. I am posting this question in MixedModels.jl, as in GLM.jl I would be able to use X, y as input for lm or glm. |
What you want to do is related to profiling the log-likelihood with respect to the fixed-effects coefficients, for which the code is in src/profile/fixefpr.jl. That code is more general than you need but it shows that you can create a reduced model by creating a fixed-effects term and then copying the response, the reterm (which needs a deepcopy or the special copy method in the file mentioned above) and the formula. Try this. using MixedModels
function dropcol(m::LinearMixedModel, j::Integer)
fe = m.feterm # model matrix X, column names, rank, etc.
x = fe.x # model matrix
fe.rank == size(x, 2) || throw(ArgumentError("m.X is not of full column rank"))
notj = deleteat!(collect(axes(x, 2)), j) # indirectly checks that j is in range
feterm = MixedModels.FeTerm(x[:, notj], fe.cnames[notj])
θbak = m.θ # save a copy of the parameter estimates
setθ!(m, m.optsum.initial) # ensure m is at initial values
mnew = LinearMixedModel(collect(m.y), feterm, deepcopy(m.reterms), m.formula)
objective!(m, θbak) # restore parameter values in m
return mnew
end
m1 = let f = @formula y ~ 1 + dept + service + (1|s) + (1|d)
fit(MixedModel, f, MixedModels.dataset(:insteval))
end
m1a = fit!(dropcol(m1, 2))
MixedModels.likelihoodratiotest(m1a, m1) |
Dear @dmbates, Thank you so much, this works perfectly. If I may, I would like to ask a follow-up question, about the correctness of my application to I applied your
Then, we contruct a new
As an adhoc example:
My point in all of this is to recreate the approach of the MAST package for single-cell analysis, where I need to fit both a Again, thank you for your help. Best, |
I think that will work. We could try to make it easier to construct a I did write a reduced set of types and methods to fit a logistic GLMM in https://embraceuncertaintybook.com/aGHQ.html If you were interested we could try to modify those for a special-purpose GLMM implementation. If this seems worthwhile to you, could you suggest where I should start reading about the MAST approach? Is the 2015 Genome Biology paper the best place to start or should I start with the vignettes in the BioConductor package? Feel free to contact me at my gmail.com (same username as on github) address to take this discussion offline. |
@MaximilianNuber Is it correct that there is only one random-effects term in the LMMs and GLMMs that you wish to fit and that it is of the form |
@dmbates Yes, the only random effect in the model is in the form For more in-depth information on your question I am preparing a mail. |
Dear all,
I am fitting MixedModels for large single cell datasets.
One approach to test for covariates is to drop a single coefficient from the modelmatrix, which belongs to one level of a categorical variable.
I have not been able to find this possibility in Julia.
As an example, let me use the iris dataset. It may not be a mixed model, but in principle it is the same.
We have the full model:
full = lm(@formula(SepalLength ~ Species), iris)
with results
My goal would be, to drop
Species: setosa
in the formula or model matrix for another linear model.This nested model would be compared to the full model by likelihood ratio test.
Everything I found so far would be dropping the
Species
variable entirely, but it is not what I want.I have played around with contrasts, where in the example the modelmatrix column for
Species: setosa
would be all zeros, but got the warning that the model is not full rank.Is there any solution to this, or possibly a workaround?
Thank you for any help,
Max
The text was updated successfully, but these errors were encountered: