Share = TRUE and FALSE within modeling function

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

Share = TRUE and FALSE within modeling function

Postby jCeradini » Mon Apr 18, 2022 11:34 pm

Howdy helpers.

Is there a way to use the RMark parameter combos function modeling approach (Gentle MARK Book: C.13 A More Organized Approach) for a combination of models with share = TRUE and others with share = FALSE? The goal is to test different covariate combos for p with share = TRUE and also the same covariate combos for p and c with share = FALSE. Specifically, I'm using a Huggins closed capture model and applying share to p and c.

If I run something like this then of course share = TRUE works for p and c:
Code: Select all
model.fun <- function(){
  p.age.grp.share <- list(formula = ~age.grp, share = TRUE)

  cml <- create.model.list("Huggins")
  return(mark.wrapper(cml, data = smamm.proc, ddl = smamm.ddl, adjust = FALSE, output = FALSE, retry = 2))
}

# Run models defined in function
model.list <- model.fun()


This returns one model with p=c and one with p(covariate), c(.):
Code: Select all
model.fun <- function(){
  p.age.grp <- list(formula = ~ge.grp)
  p.age.grp.share <- list(formula = ~age.grp, share = TRUE)

  cml <- create.model.list("Huggins")
  return(mark.wrapper(cml, data = smamm.proc, ddl = smamm.ddl, adjust = FALSE, output = FALSE, retry = 2))
}

# Run models defined in function
model.list <- model.fun()


But, of course, share = TRUE no longer works when you add a formula for c within the function. So, it is not possible to test different covariates for p and c where some models have share = TRUE and some have FALSE, which is the goal.

If it isn't possible as one integrated function, then what about running two separate functions, one for share=TRUE and one for FALSE, for the same set of covariates, and then using collect.models() to collect them all into one AIC table? I realize that doesn't work because, as far as I can tell, you have to run models outside of the function approach for collect.models() to work, but am wondering if there is some similar way or workaround to combine the sets .

Sorry if this is answered elsewhere, please just point me to the post or reference. I haven't found an answer in forum searching or reading of RMark docs, but maybe I just did a bad job searching :?

Thanks!
Joe
jCeradini
 
Posts: 72
Joined: Mon Oct 13, 2014 3:53 pm

Re: Share = TRUE and FALSE within modeling function

Postby jlaake » Tue Apr 19, 2022 11:39 am

See ? edwards.eberhardt example. May not be able to use create.model.list. Never tried what you are doing.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Share = TRUE and FALSE within modeling function

Postby jCeradini » Wed Apr 20, 2022 10:50 pm

Thanks Jeff. I'll re-post if I come up with something.
jCeradini
 
Posts: 72
Joined: Mon Oct 13, 2014 3:53 pm

Re: Share = TRUE and FALSE within modeling function

Postby jCeradini » Sat Apr 23, 2022 1:07 pm

Well, it's far from elegant, but this is my current workaround. Only has some value if you are dealing with a larger number of covariate combos (than shown in this example), otherwise probably simpler just to write out each model.

Code: Select all
# p share formulas
#~~~~~~~~~~~~~~~~~~
p.constant.share <- list(formula = ~1, share = TRUE)
p.age.grp.share <- list(formula = ~age.grp, share = TRUE)
p.genus.grp.share <- list(formula = ~genus.grp, share = TRUE)

# p share cml
cml.share <- create.model.list("Huggins")
cml.share
cml.share$c <- "" # add blank column for c so can rbind later

# remove p share formulas so next cml doesn't grab them again
rm(list = c(cml.share$p))

# p and c no share formulas
#~~~~~~~~~~~~~~~~~~~~~~~~~~~
p.constant <- list(formula = ~1)
p.age.grp <- list(formula = ~age.grp)
p.genus.grp <- list(formula = ~genus.grp)

c.constant <- list(formula = ~1)
c.age.grp <- list(formula = ~age.grp)
c.genus.grp <- list(formula = ~genus.grp)

# p and c no share cml
cml.noshare <- create.model.list("Huggins")
cml.noshare

# Combine cml.share and cml.noshare into one dataframe
#~~~~~~~~~
cml.final <- rbind(cml.share, cml.noshare)

# Rerun p share formulas (removed earlier) b/c those objects need to
# be present for mark.wrapper
#~~~~~~~~~~~~~~~~~~
p.constant.share <- list(formula = ~1, share = TRUE)
p.age.grp.share <- list(formula = ~age.grp, share = TRUE)
p.genus.grp.share <- list(formula = ~genus.grp, share = TRUE)

# Run models
#~~~~~~~~~~~~
test <- mark.wrapper(cml.final, data = smamm.proc, ddl = smamm.ddl, adjust = FALSE, output = FALSE, retry = 2)


Code: Select all
 test$model.table$model
 [1] "p(~age.grp)c(~1)"         
 [2] "p(~genus.grp)c(~age.grp)" 
 [3] "p(~1)c(~1)"               
 [4] "p(~genus.grp)c(~genus.grp)"
 [5] "p(~genus.grp)c(~1)"       
 [6] "p(~age.grp)c(~genus.grp)" 
 [7] "p(~1)c(~age.grp)"         
 [8] "p(~1)c(~genus.grp)"       
 [9] "p(~age.grp)c(~age.grp)"   
[10] "p(~genus.grp)c()"         
[11] "p(~1)c()"                 
[12] "p(~age.grp)c()"   
jCeradini
 
Posts: 72
Joined: Mon Oct 13, 2014 3:53 pm

Re: Share = TRUE and FALSE within modeling function

Postby jlaake » Sat Apr 23, 2022 3:29 pm

You can also just run the model sets in different functions and then use merge.mark to merge the marklists.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: No registered users and 14 guests

cron