# [R] multinom() and parameters

Mon May 18 18:07:15 CEST 2009

```Dear All,

I am doing multinomial logistic regression with multinom().

I have to process many variables and I created a function which biulds the models and format the results (see below).
It works prefect when I set the variables and the dataset locally
Outcome <- "Group"
covars <- "age"
dta <- my.data
mod<-multinom(as.formula(paste(Outcome,"~",covars)), data = dta,na.action =na.omit,Hess=T)

But it says that it cannot find the variables and dataset when I start using the function
my.multinom("Group", "age", dta = my.data)

There should be some problems with passing the parameters from multinom() to nnet().

With the best regards,

Biostatistician,
Robertson Centre for Biostatistics
University of Glasgow

# the function
my.multinom<-function(Outcome,covars,dta){
mod<-multinom(as.formula(paste(Outcome,"~",covars)), data = dta,na.action =na.omit,Hess=T)
mod.sum<- summary(mod,Wald=T)
p <- 1-pchisq((mod.sum\$Wald[,-1])^2,1)
coef <-c(mod.sum\$coefficients[,-1])
se <-c(mod.sum\$standard.errors[,-1])
ci <- paste(round(exp(coef),3), "(",round(exp(coef-1.96*se),3), ":",round(exp(coef+1.96*se),3),"), p=",p.format(p),sep="")

varnames<-dimnames(mod.sum\$coefficients)[[2]][-1]
Variable<-c(unlist(lapply(varnames,function(zz){
mm<- match(zz,names(HV.all))
if(!is.na(mm)) attributes(HV.all[,zz])\$label
else zz
})))

varnms<- unlist(lapply(Variable,function(zz){paste (dimnames(mod.sum\$coefficients)[[1]],":",zz)}))
out<-   cbind(varnms, ci)
dimnames(out)[[2]]<-c("Parameter","HR (95%CI),p" )
out
}

The University of Glasgow, charity number SC004401

```