Page 1 of 1

adding model names to collect.models

PostPosted: Tue Jun 03, 2014 4:24 pm
by markmiller
Occasionally I wish I could add model names to the AICc table created by collect.models().
This seems like it might be helpful when models are numerous and complex and parameterizations
differ only slightly. I think I figured out a way, using the code below.

However, my approach intuitively does not appear to be very efficient. I also wonder a
little how general or robust it is.

Does anyone know of an easier way?

The only other way I have thought of so far would be to modify the model.table() function
itself and I have not yet figured out how to do that.

Here is how I am adding the model names to the AICc table:

Code: Select all
###################################################################################

p             = list(formula =~ -1 + stratum + session)
Delta         = list(formula =~  1                    )

Phi0          = list(formula =~ -1 + stratum          )
Psi           = list(formula =~ -1 + stratum + time   )
R             = list(formula =~ -1 + stratum + time   )

model.A  = mark(rd.processed, rd.ddl,
                model.parameters = list( p     = p    ,
                                         Delta = Delta,
                                         Phi0  = Phi0 ,
                                         Psi   = Psi  ,
                                         R     = R    ))

model.A

###################################################################################

p             = list(formula =~  1                    )
Delta         = list(formula =~  1                    )

Phi0          = list(formula =~ -1 + stratum          )
Psi           = list(formula =~ -1 + stratum + time   )
R             = list(formula =~ -1 + stratum + time   )

model.B  = mark(rd.processed, rd.ddl,
                model.parameters = list( p     = p    ,
                                         Delta = Delta,
                                         Phi0  = Phi0 ,
                                         Psi   = Psi  ,
                                         R     = R    ))

model.B

###################################################################################

my.table <- collect.models(, adjust = FALSE, table = TRUE)

my.names <- collect.model.names( lx=ls())

names.in.table <- as.numeric(row.names(model.table(my.table, adjust = FALSE)))

my.model.names <- my.names[names.in.table]

my.table.with.model.names <- cbind(my.model.names, my.table$model.table)
my.table.with.model.names

###################################################################################

Re: adding model names to collect.models

PostPosted: Tue Jun 03, 2014 4:31 pm
by jlaake
See help for model.table. The default is model.name=TRUE. I think what you want is model.name=FALSE. Just use the names you want. What I do is name them p.1,p.2,... and Phi.1,Phi.2 etc and then set model.name=FALSE with mark.wrapper and I get things like p.1.Phi.1 etc. But you can use whatever naming convention you want.

model.name if TRUE uses the model.name in each mark object which uses
formula notation. If FALSE it uses the R names for the model obtained from
collect.model.names or names assigned to marklist elements

Re: adding model names to collect.models

PostPosted: Tue Jun 03, 2014 5:32 pm
by markmiller
Thank you, Jeff. That worked. I had never used the model.table() function until today. Here is the code:

Code: Select all
###################################################################################

my.table <- collect.models(, adjust = FALSE, table = TRUE)

model.table(my.table, model.name = FALSE, adjust=FALSE)

###################################################################################