create.model.list vs collect.models

posts related to the RMark library, which may not be of general interest to users of 'classic' MARK

create.model.list vs collect.models

Postby WiPhi » Fri Apr 14, 2017 2:55 pm

The clear strength of RMark is in being able to rapidly construct and compare many models and extract output for further analysis.

I was wondering what is the difference between an object created by returning the result of mark.wrapper() on a list of models specified within a function and the object created by running collect.models after each model is run separately?

Appendix C shows many operations using the object created by collect.models() and I would like to do the equivalent on the object created by my function which returns the results of mark.wrapper on a model list.

For example:

dipper.cjs.results=remove.mark(dipper.cjs.results, c(11,12)

works to remove models from a collect.models object but not an object returned by mark.wrapper() on a model list inside a function.

Perhaps another way of asking this question is how to I make the object returned by a function fitting many models equivalent in structure to an object created by collect.models()?
WiPhi
 
Posts: 27
Joined: Thu Mar 31, 2016 6:15 pm

Re: create.model.list vs collect.models

Postby jlaake » Mon Apr 17, 2017 7:20 pm

They have identical structures and both are of class marklist and should both be able to be manipulated the same way. An example is given below. They contain different models but I show how remove.mark works for both approaches. Not sure why it didn't work for you. I started with collect.models approach and it evolved into the mark.wrapper approach as I developed RMark. Both are viable approaches. You can also create the model list from all combinations and then delete a subset you may not want before you pass it to mark.wrapper. The result from create.model.list is simply a dataframe with a column for each parameter and a character string for the parameter specification (e.g., p.sex for p.sex=list(formula=~sex)).

Code: Select all
run.dipper=function()
{
#
# Process data
#
dipper.processed=process.data(dipper,groups=("sex"))
#
# Create default design data
#
dipper.ddl=make.design.data(dipper.processed)
#
# Add Flood covariates for Phi and p that have different values
#
dipper.ddl$Phi$Flood=0
dipper.ddl$Phi$Flood[dipper.ddl$Phi$time==2 | dipper.ddl$Phi$time==3]=1
dipper.ddl$p$Flood=0
dipper.ddl$p$Flood[dipper.ddl$p$time==3]=1
#
#  Define range of models for Phi
#
Phidot=list(formula=~1)
Phitime=list(formula=~time)
Phisex=list(formula=~sex)
Phisextime=list(formula=~sex+time)
Phisex.time=list(formula=~sex*time)
PhiFlood=list(formula=~Flood)
#
#  Define range of models for p
#
pdot=list(formula=~1)
ptime=list(formula=~time)
psex=list(formula=~sex)
psextime=list(formula=~sex+time)
psex.time=list(formula=~sex*time)
pFlood=list(formula=~Flood)
#
# Run assortment of models
#
dipper.phidot.pdot          =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phidot,p=pdot))
dipper.phidot.pFlood         =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phidot,p=pFlood))
dipper.phidot.psex           =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phidot,p=psex))
dipper.phidot.ptime          =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phidot,p=ptime))
dipper.phidot.psex.time      =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phidot,p=psex.time))
dipper.phitime.ptime         =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phitime, p=ptime))
dipper.phitime.pdot          =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phitime,p=pdot))
dipper.phitime.psex      =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phitime,p=psex))
dipper.phitime.psex.time   =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phitime,p=psex.time))
dipper.phiFlood.pFlood       =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=PhiFlood, p=pFlood))
dipper.phisex.pdot           =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisex,p=pdot))
dipper.phisex.psex           =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisex,p=psex))
dipper.phisex.psex.time           =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisex,p=psex.time))
dipper.phisex.ptime          =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisex,p=ptime))
dipper.phisextime.psextime   =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisextime,p=psextime))
dipper.phisex.time.psex.time   =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisex.time,p=psex.time))
dipper.phisex.time.psex    =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisex.time,p=psex))
dipper.phisex.time.pdot      =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisex.time,p=pdot))
dipper.phisex.time.ptime   =mark(dipper.processed,dipper.ddl,
                 model.parameters=list(Phi=Phisex.time,p=ptime))
#
# Return model table and list of models
#
return(collect.models() )
}

dipper.collect=run.dipper()


run.dipper=function()
{
#
# Process data
#
dipper.processed=process.data(dipper,groups=("sex"))
#
# Create default design data
#
dipper.ddl=make.design.data(dipper.processed)
#
# Add Flood covariates for Phi and p that have different values
#
dipper.ddl$Phi$Flood=0
dipper.ddl$Phi$Flood[dipper.ddl$Phi$time==2 | dipper.ddl$Phi$time==3]=1
dipper.ddl$p$Flood=0
dipper.ddl$p$Flood[dipper.ddl$p$time==3]=1
#
#  Define range of models for Phi
#
Phi.dot=list(formula=~1)
Phi.time=list(formula=~time)
Phi.sex=list(formula=~sex)
Phi.Flood=list(formula=~Flood)
#
#  Define range of models for p
#
p.dot=list(formula=~1)
p.time=list(formula=~time)
p.sex=list(formula=~sex)
#
# Run assortment of models
#
cml=create.model.list("CJS")
results=mark.wrapper(cml,data=dipper.processed,ddl=dipper.ddl)
# Return model table and list of models
#
return(results )
}

dipper.wrapper=run.dipper()

dipper.collect
dipper.collect=remove.mark(dipper.collect,c(6,1))
dipper.collect
dipper.wrapper
dipper.wrapper=remove.mark(dipper.wrapper,c(4,5))
dipper.wrapper
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: create.model.list vs collect.models

Postby WiPhi » Wed Apr 19, 2017 12:27 pm

Thanks,
Yes, I had an error in my code that produced the problem. I was attempt to remove many models and I included the last item in the list, which is a model table, not a model, creating an error. thanks for the tip on modifying the model list before calling mark.wrapper.
WiPhi
 
Posts: 27
Joined: Thu Mar 31, 2016 6:15 pm


Return to RMark

Who is online

Users browsing this forum: No registered users and 6 guests

cron