Compare model fits of two GAM

1.5k Views Asked by At

I have a matrix Expr with rows representing variables and columns samples. I have a categorical vector called groups (containing either "A","B", or "C") I want to test which of variables 'Expr' can be explained by the fact that the sample belong to a group.

My strategy would be modelling the problem with a generalized additive model (with a negative binomial distribution). And then I want use a likelihood ratio test in a variable wise way to get a p value for each variable. I do:

require(VGAM)
m <- vgam(Expr ~ group, family=negbinomial)
m_alternative <- vgam(Expr ~ 1, family=negbinomial)

and then:

lr <- lrtest(m, m_alternative)

The last step is wrong because it is testing the overall likelihood ratio of the two model not the variable wise. Instead of a single p value I would like to get a vector of the p-values for every variable.

How should I do it? (I am very new to R, so forgive me my stupidity)

1

There are 1 best solutions below

0
On

It sounds like you want to use Expr as your predictors It think you may have your formula backwards. The response should be on the left, so I guess that's groups in your case.

If Expr is a data.frame, you can do regression on all variables with

m <- vgam(group ~ ., Expr, family=negbinomial)

If class(Expr)=="matrix", then

m <- vgam(group ~ Expr, family=negbinomial)

probably should work, but you may just get slightly odd looking coefficient labels.