Skip to content
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

In focei, text covariates are converted to doubles (but it appears that the model still estimates) #274

Closed
billdenney opened this issue Oct 27, 2022 · 2 comments · Fixed by #278

Comments

@billdenney
Copy link
Contributor

When looking at that code, any covariates would also be converted to doubles, and that seems like a problem, too. It would break Boolean checks like (STUDYID == "Study 1"). So, should covariates (.covNames in the code here) not be converted to doubles, either?

Originally posted by @billdenney in #272 (comment)

@billdenney
Copy link
Contributor Author

The reprex is below. Note that the model estimates the value of cllow, but it also reports that all of the covariates are NA. I assume that the best would be to turn off covariate conversions, but I don't want to unintentionally break things there.

# run with the fix-272 branch
devtools::load_all("c:/git/nlmixr2/nlmixr2est/")
#> ℹ Loading nlmixr2est
#> Loading required package: nlmixr2data

one_compartment_textcov <- function() {
  ini({
    tka <- 0.45
    tcl <- 1
    tv <- 3.45
    cllow <- 0.001
    eta.ka ~ 0.6
    eta.cl ~ 0.3
    eta.v ~ 0.1
    add.sd <- 0.7
  })
  # and a model block with the error sppecification and model specification
  model({
    ka <- exp(tka + eta.ka)
    cl <- exp(tcl + eta.cl + cllow*(LowID == "Yes"))
    v <- exp(tv + eta.v)
    d/dt(depot) = -ka * depot
    d/dt(center) = ka * depot - cl / v * center
    cp = center / v
    cp ~ add(add.sd)
  })
}

fitdata <- theo_sd
fitdata$ID <- paste("theo", fitdata$ID)
fitdata$LowID <- ifelse(as.numeric(theo_sd$ID) < 7, "Yes", "No")
fit <- nlmixr2(one_compartment_textcov, fitdata,  est="focei", control = foceiControl(print = 0))
#> rxode2 2.0.10.9000 using 8 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
#> calculating covariance matrix
#> done
#> → Calculating residuals/tables
#> ✔ done
#> → compress origData in nlmixr2 object, save 8512
#> → compress parHist in nlmixr2 object, save 2560
fit
#> ── nlmixr² FOCEi (outer: nlminb) ──
#> 
#>          OBJF      AIC      BIC Log-likelihood Condition Number
#> FOCEi 116.807 375.4068 398.4692      -179.7034         261.6035
#> 
#> ── Time (sec fit$time): ──
#> 
#>         setup optimize covariance table other
#> elapsed 0.016    0.938      0.938  0.06 0.998
#> 
#> ── Population Parameters (fit$parFixed or fit$parFixedDf): ──
#> 
#>            Est.     SE    %RSE    Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka       0.463  0.282    60.9         1.59 (0.914, 2.76)     69.8      1.20% 
#> tcl        1.01  0.545      54         2.74 (0.943, 7.99)     26.8      4.08% 
#> tv         3.46 0.0943    2.73          31.8 (26.4, 38.2)     14.0      10.5% 
#> cllow  0.000994 0.0418 4.2e+03 0.000994 (-0.0809, 0.0829)                     
#> add.sd    0.694                                     0.694                     
#>  
#>   Covariance Type (fit$covMethod): |r|
#>   No correlations in between subject variability (BSV) matrix
#>   Full BSV covariance (fit$omega) or correlation (fit$omegaR; diagonals=SDs) 
#>   Distribution stats (mean/skewness/kurtosis/p-value) available in fit$shrink 
#>   Information about run found (fit$runInfo):
#>    • column 'LowID' has only 'NA' values for id '12' 
#>    • column 'LowID' has only 'NA' values for id '11' 
#>    • column 'LowID' has only 'NA' values for id '10' 
#>    • column 'LowID' has only 'NA' values for id '9' 
#>    • column 'LowID' has only 'NA' values for id '8' 
#>    • column 'LowID' has only 'NA' values for id '7' 
#>    • column 'LowID' has only 'NA' values for id '6' 
#>    • column 'LowID' has only 'NA' values for id '5' 
#>    • column 'LowID' has only 'NA' values for id '4' 
#>    • column 'LowID' has only 'NA' values for id '3' 
#>    • column 'LowID' has only 'NA' values for id '2' 
#>    • column 'LowID' has only 'NA' values for id '1' 
#>    • zero gradient replaced with small number (0.000000) 
#>    • gradient problems with initial estimate and covariance; see $scaleInfo 
#>    • using R matrix to calculate covariance, can check sandwich or S matrix with $covRS and $covS 
#>    • R matrix non-positive definite but corrected by R = sqrtm(R%*%R) 
#>    • S matrix non-positive definite 
#>    • last objective function was not at minimum, possible problems in optimization 
#>    • ETAs were reset to zero during optimization; (Can control by foceiControl(resetEtaP=.)) 
#>    • initial ETAs were nudged; (can control by foceiControl(etaNudge=., etaNudge2=)) 
#>    • column 'LowID' has only 'NA' values for id 'theo 1' 
#>    • column 'LowID' has only 'NA' values for id 'theo 2' 
#>    • column 'LowID' has only 'NA' values for id 'theo 3' 
#>    • column 'LowID' has only 'NA' values for id 'theo 4' 
#>    • column 'LowID' has only 'NA' values for id 'theo 5' 
#>    • column 'LowID' has only 'NA' values for id 'theo 6' 
#>    • column 'LowID' has only 'NA' values for id 'theo 7' 
#>    • column 'LowID' has only 'NA' values for id 'theo 8' 
#>    • column 'LowID' has only 'NA' values for id 'theo 9' 
#>    • column 'LowID' has only 'NA' values for id 'theo 10' 
#>    • column 'LowID' has only 'NA' values for id 'theo 11' 
#>    • column 'LowID' has only 'NA' values for id 'theo 12' 
#>    • NAs introduced by coercion 
#>   Censoring (fit$censInformation): No censoring
#>   Minimization message (fit$message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object fit is a modified tibble): ──
#> # A tibble: 132 × 23
#>   ID      TIME    DV  PRED    RES   WRES IPRED   IRES  IWRES CPRED   CRES  CWRES
#>   <fct>  <dbl> <dbl> <dbl>  <dbl>  <dbl> <dbl>  <dbl>  <dbl> <dbl>  <dbl>  <dbl>
#> 1 theo 1  0     0.74  0     0.74   1.07   0     0.74   1.07   0     0.74   1.07 
#> 2 theo 1  0.25  2.84  3.26 -0.424 -0.227  3.85 -1.01  -1.45   3.22 -0.380 -0.179
#> 3 theo 1  0.57  6.57  5.83  0.736  0.297  6.78 -0.215 -0.310  5.78  0.791  0.288
#> # … with 129 more rows, and 11 more variables: eta.ka <dbl>, eta.cl <dbl>,
#> #   eta.v <dbl>, depot <dbl>, center <dbl>, ka <dbl>, cl <dbl>, v <dbl>,
#> #   tad <dbl>, dosenum <dbl>, LowID <dbl>

Created on 2022-10-27 with reprex v2.0.2

@mattfidler
Copy link
Contributor

Yes turn off the conversions.

I think this was accidentally turned on by me in nlmixr2 rewrite.

@mattfidler mattfidler linked a pull request Oct 28, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants