-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: method for retrieving initial parameter estimates #29
Comments
@kyleam Im currently doing something like this: get_theta_inits <- function(ctl){
# Tabulate initial values and bounds
theta_inits <- purrr::map_dfc(c("init", "low", "up"), function(type){
theta_inits <- nmrec::get_theta(ctl, type = type)
tibble::tibble(!!rlang::sym(type) := theta_inits)
})
# Tabulate presence of FIXED parameters
theta_inits_fixed <- nmrec::get_theta(ctl, mark_flags = "fix")
theta_inits$fixed <- attr(theta_inits_fixed, "nmrec_flags")$fixed
} > theta_inits
# A tibble: 12 × 4
init low up fixed
<dbl> <dbl> <dbl> <lgl>
1 0.7 NA NA TRUE
2 0.7 NA NA FALSE
3 2 NA NA FALSE
4 2 NA NA FALSE
5 0.7 NA NA FALSE
6 0.7 NA NA FALSE
7 2 NA NA FALSE
8 2 NA NA FALSE
9 0.7 NA NA FALSE
10 0.7 NA NA FALSE
11 0.3 NA NA FALSE
12 4 NA NA TRUE FWIW im not proposing returning a dataframe, just showcasing that im executing the call a total of 4 times to get the information I need (I realize I could do it 3 times, but this seemed more organized/readable) |
I'd prefer not to. I'd like to avoid arguments that change the structure of the return value. We could make
Hmm I'm surprised you want to map to a list result. To jitter, presumably you want access to all of those matrices individually, so I think it'd be more to the point and readable to do something like
But anyway, that's of course just subjective and depends on context. In either case, my view is that the caller (so bbr in this case) should do the handling for getting multiple types. |
As with the |
I had a thought about prior blocks btw. I think it could be worth looking at > MODEL_DIR_C <- system.file("model", "nonmem", "complex", package = "bbr")
> .mod <- read_model(file.path(MODEL_DIR_C, "example2_saemimp"))
> .mod %>% param_labels() %>% apply_indices() %>% head(13)
# A tibble: 13 × 5
parameter_names label unit type param_type
<chr> <chr> <chr> <chr> <chr>
1 THETA1 "" "LCLM" "" THETA
2 THETA2 "" "LCLF" "" THETA
3 THETA3 "" "CLAM" "" THETA
4 THETA4 "" "CLAF" "" THETA
5 THETA5 "" "LV1M" "" THETA
6 THETA6 "" "LV1F" "" THETA
7 THETA7 "" "V1AM" "" THETA
8 THETA8 "" "V1AF" "" THETA
9 THETA9 "" "MU_3" "" THETA
10 THETA10 "" "MU_4" "" THETA
11 THETA11 "" "SDSL" "" THETA
12 THETA12 "" "" "" THETA # this is a prior record
13 OMEGA(1,1) "" "" "[p]" OMEGA |
Sorry, I don't understand what the specific question is. (I think you're saying something beyond this, but if part of it is that |
I was in part suggesting we could refactor them to use As an aside, I was wondering if we could add the option to return the block type for matrices, which would return either "diagonal" or "block". The only way I see I can get that information currently, is via nmrec::get_omega(ctl, mark_flags = c("fix", "type")) |
Again, I'm not keen on doing anything about the non-informative record names at the nmrec level. If you really want to do it, I'd suggest do it on the bbr side first making use of what nmrec will give you publicly. But, as I mentioned before, I don't think looking at the
It's returning the full matrix, so don't you already know each index? |
Yeah I think modifying
Yes I could get the indices that way, but I was trying to take advantage of those two > param_labels(.mod) %>% apply_indices(.omega = c(block(4), block(4))) %>%
dplyr::filter(param_type != "THETA") %>% head(15)
# A tibble: 15 × 5
parameter_names label unit type param_type
<chr> <chr> <chr> <chr> <chr>
1 OMEGA(1,1) "" "" [p] OMEGA
2 OMEGA(2,1) "" "" [f] OMEGA
3 OMEGA(2,2) "" "" [p] OMEGA
4 OMEGA(3,1) "" "" [f] OMEGA
5 OMEGA(3,2) "" "" [f] OMEGA
6 OMEGA(3,3) "" "" [p] OMEGA
7 OMEGA(4,1) "" "" [f] OMEGA
8 OMEGA(4,2) "" "" [f] OMEGA
9 OMEGA(4,3) "" "" [f] OMEGA
10 OMEGA(4,4) "" "" [p] OMEGA
11 OMEGA(5,5) "" "" [A] OMEGA
12 OMEGA(6,5) "" "" [A] OMEGA
13 OMEGA(6,6) "" "" [A] OMEGA
14 OMEGA(7,5) "" "" [A] OMEGA
15 OMEGA(7,6) "" "" [A] OMEGA Those functions only work with defined values, so the following would not work with the full OMEGA matrix: > param_labels(.mod) %>% apply_indices(.omega = c(block(8))) %>% dplyr::filter(param_type != "THETA") %>% head(15)
Error in apply_indices(., .omega = c(block(8))) :
Found 20 parameters for OMEGA but `.omega` argument specifies 36 Perhaps this is a bit overkill and out of scope though |
Let's see what the options are on bbr's end for handling the full matrix before adding redundant info on nmrec's end. If we decide that using these helpers is really the cleanest/easiest way to go, then we can revisit tacking on additional info. |
@barrettk I haven't fully digested all of this, but I'll jump in to say that I would prefer not to rely on As an addendum, I think converting these to use |
bbr is adding a feature to jitter the initial estimates from a control stream. To do so, it could loop through the initial estimate options and jitter each one, but it's probably more convenient to be able to work with the values in their native form (i.e. a numeric vector for THETA or square matrix for OMEGA/SIGMA). Note that naming these new functions get_{theta,omega,sigma} would align nicely with the existing set_{theta,omega,sigma} functions, but the get_* names would collide with bbr functions if a user attaches both bbr and nmrec. Re: #29
The original motivation stems from here, though I thought it would be nice to have a neat way to return the initial parameter estimates before this step. Additionally, I think scientists might appreciate the ability to easily retrieve and format initial estimates in some reports, that could be fed into
pmtables
or some other formatting function.Requirements
FIXED
FIXED
. In an offline discussion, it was noted thatFIX
in block matrices fixes the entire record, though specific parameters can be fixed for diagonal matrices. It was suggested that a logical matrix might be the way to go here.Initial Prototype
Note that this prototype uses dependencies that would not make sense to utilize in this package; I just used them for nicer formatting in a
bbr
environment. See this comment for some examples.Code
nmrec prototype
After putting together this prototype and discussing with @kyleam, he put together a prototype more in line with the
nmrec
code base. From my testing so far, thenmrec
prototype Kyle put together seems to return everything I need to put together abbr
wrapper.set_{theta,omega,sigma}
functions). I wonder if those should be an attribute (probably not) or returned in some other fashion. Im not opposed to just filtering them out, and mentioning that in the docs though.As Kyle noted in the
TODO
sections, I think we may have to figure out better names to avoid the overlap withbbr
functions (get_{theta,omega,sigma}
functions). Somewhat of a shame because I like the naming convention in both cases, but obviously that's a good point given that it's quite possible a user could have both packages loaded.The text was updated successfully, but these errors were encountered: