add_remove_covs: Add/remove a covariate to a NONMEM model

add_remove_covsR Documentation

Add/remove a covariate to a NONMEM model

Description

[Stable]

Follows PsN coding conventions to add covariates into a model. The advantage is no need to create a .scm file, just directly modify the NONMEM control file contents. This function is used by covariate_step_tibble() for stepwise covariate model development.

Usage

add_cov(
  ctl,
  param,
  cov,
  state = 2,
  continuous = TRUE,
  time_varying,
  additional_state_text = list(),
  id_var = "ID",
  force = FALSE,
  force_TV_var = FALSE,
  init,
  lower,
  upper
)

remove_cov(
  ctl,
  param,
  cov,
  state = 2,
  continuous = TRUE,
  time_varying,
  id_var = "ID"
)

Arguments

ctl

An nm object or an object coercible to ctl_list.

param

Character. Name of parameter.

cov

Character. Name of covariate.

state

Numeric or character. Number or name of state (see details).

continuous

Logical (default = TRUE). Is covariate continuous?

time_varying

Optional logical. is the covariate time varying?

additional_state_text

Optional character (default = empty). Custom state variable to be passed to param_cov_text.

id_var

Character (default = "ID"). Needed if time_varying is missing.

force

Logical (default = 'FALSEā€œ). Force covariate in even if missing values found.

force_TV_var

Logical (default = FALSE). Force covariates only on TV notation parameters.

init

Optional numeric/character vector. Initial estimate of additional parameters.

lower

Optional numeric/character vector. lower bound of additional parameters.

upper

Optional numeric/character vector. Upper bound of additional parameters.

Details

Available states:

"2" or "linear"

PARCOV= ( 1 + THETA(1)*(COV -median))

"3" or "hockey-stick"

IF(COV.LE.median) PARCOV = ( 1 + THETA(1)*(COV - median)) IF(COV.GT.median) PARCOV = ( 1 + THETA(2)*(COV - median))

"4" or "exponential"

PARCOV= EXP(THETA(1)*(COV - median))

"5" or "power"

PARCOV= ((COV/median)**THETA(1))

"power1"

PARCOV= ((COV/median))

"power0.75"

PARCOV= ((COV/median)**0.75)

"6" or "log-linear"

PARCOV= ( 1 + THETA(1)*(LOG(COV) - log(median)))

remove_cov only works with covariates added with add_cov.

Value

An nm object with modified ctl_contents field.

See Also

covariate_step_tibble(), test_relations()

Examples


# create example object m1 from package demo files
exdir <- system.file("extdata", "examples", "theopp", package = "NMproject")
m1 <- new_nm(run_id = "m1", 
             based_on = file.path(exdir, "Models", "ADVAN2.mod"),
             data_path = file.path(exdir, "SourceData", "THEOPP.csv"))

temp_data_file <- paste0(tempfile(), ".csv")

## dataset has missing WTs so create a new one and assign this to the run
input_data(m1) %>% 
  dplyr::group_by(ID) %>%
  dplyr::mutate(WT = na.omit(WT)) %>%
  write_derived_data(temp_data_file)
  
m1 <- m1 %>% data_path(temp_data_file)
 
m1WT <- m1 %>% child("m1WT") %>%
  add_cov(param = "V", cov = "WT", state = "power")

m1 %>% dollar("PK")
m1WT %>% dollar("PK")  ## notice SCM style code added

nm_diff(m1WT)

## Not run: 
run_nm(c(m1, m1WT))
rr(c(m1, m1WT))
summary_wide(c(m1, m1WT)) 

## End(Not run)

unlink(temp_data_file)


# create example object m1 from package demo files
exdir <- system.file("extdata", "examples", "theopp", package = "NMproject")
m1 <- new_nm(run_id = "m1", 
             based_on = file.path(exdir, "Models", "ADVAN2.mod"),
             data_path = file.path(exdir, "SourceData", "THEOPP.csv"))

temp_data_file <- paste0(tempfile(), ".csv")

## dataset has missing WTs so create a new one and assign this to the run
input_data(m1) %>% 
  dplyr::group_by(ID) %>%
  dplyr::mutate(WT = na.omit(WT)) %>%
  write_derived_data(temp_data_file)
  
m1 <- m1 %>% data_path(temp_data_file)
 
m1WT <- m1 %>% child("m1WT") %>%
  add_cov(param = "V", cov = "WT", state = "power")

m1 %>% dollar("PK")
m1WT %>% dollar("PK")  ## notice SCM style code added

## reverse this by removing WT

m1noWT <- m1WT %>% child("m1noWT") %>%
  remove_cov(param = "V", cov = "WT") 
  
m1noWT %>% dollar("PK")
m1noWT %>% dollar("THETA")

unlink(temp_data_file)


NMproject documentation built on Sept. 30, 2022, 1:06 a.m.