I have a scenario in which I'm using multinom (from NNET package) to perform multinomial regression over a set of 100+ genes (a given gene is an independent variable in each multinomial regression). I have the following setup for generating the models, which runs successfully.

formulas <- sapply(iv_list, function(x) as.formula(paste0("Outcome ~","`",x,"`","+ Covariate")))

models <- lapply(formulas, function(x){multinom(x, data = Data)})

My Q is how to extract the beta coefficient and standard errors for the set of 100+ genes

I tried the below...

summaries <- lapply(models,summary)

...it yields the following error:

Error in formula.character(object, env = baseenv()) : invalid formula "CAPN9": not a call

CAPN9 being one of the gene names for which a multinomial model was fit

I'd really appreciate any help!


1 Answer 1



models <- lapply(formulas, function(x){multinom(x, data = Data, Hess = TRUE)})

When you don't ask for the Hessian matrix (to get sampling variance-covariance) it has to be produced when calling summary. R is trying to reproduce the call and run the multinom model again to get the Hessian. The formulas provided are not parsing right as they were passed through lapply (which records them as x if you look at each model's result object/list). nnet is using that x formula to try to work backwards and re-run the model, but it is failing to parse right, which is causing the error.

All this is avoided by obtaining the Hessian up-front in the initial model call.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.