Skip to contents

Save a fitted model object to a series of files

Usage

saveFit(fit, file, zip = TRUE, data = .nlmixr2saveData())

# S3 method for class 'nlmixr2FitCore'
saveFit(fit, file, zip = TRUE, data = .nlmixr2saveData())

# S3 method for class 'nlmixr2FitData'
saveFit(fit, file, zip = TRUE, data = .nlmixr2saveData())

# Default S3 method
saveFit(fit, file, zip = TRUE, data = .nlmixr2saveData())

Arguments

fit

the fitted model object

file

the base name of the files to save the fit to. It may include a directory, e.g. "path/to/fit": the files are written there (the directory is created if needed) and the archive path/to/fit.zip holds them under the bare name fit, so it can be moved and loaded from anywhere.

zip

Boolean indicating if the files should be zipped.

data

Boolean indicating whether the original dataset (origData) is stored in the saved fit. When FALSE it is omitted, producing a fit that can be shared without the subject-level data (see nlmixr2saveShare()). Defaults to getOption("nlmixr2save.data", TRUE).

Value

nothing, called for side effects

Author

Matthew L. Fidler

Examples

# \donttest{
  if (requireNamespace("nlmixr2est", quietly=TRUE) &&
        requireNamespace("nlmixr2data", quietly=TRUE) &&
        requireNamespace("withr")) {
    library(nlmixr2est)
    library(nlmixr2data)
    withr::with_tempdir({
      one.cmt <- function() {
        ini({
          tka <- 0.45
          tcl <- log(c(0, 2.7, 100))
          tv <- 3.45
          eta.ka ~ 0.6
          eta.cl ~ 0.3
          eta.v ~ 0.1
          add.sd <- 0.7
        })
        model({
          ka <- exp(tka + eta.ka)
          cl <- exp(tcl + eta.cl)
          v  <- exp(tv + eta.v)
          linCmt() ~ add(add.sd)
        })
      }

      fit <- nlmixr2(one.cmt, theo_sd, est="focei")

      saveFit(fit) # saved to fit.zip
      fit2 <- loadFit(fit) # load fit.zip

      if (file.exists("fit.zip")) {
         unlink("fit.zip")
      }

      print(fit2)
    })
  }
#>  
#>  
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> → Calculating residuals/tables
#> ✔ done
#> ℹ saving fit item: .fdFullCov
#> ℹ saving fit item: .fdFullS
#> ℹ saving fit item: .rownum
#> ℹ saving fit item: AIC
#> ℹ saving fit item: BIC
#> ℹ saving fit item: R
#> ℹ saving fit item: R.0
#> ℹ saving fit item: R.E
#> ℹ saving fit item: R.pd
#> ℹ saving fit item: Rinv
#> ℹ saving fit item: S
#> ℹ saving fit item: S.E
#> ℹ saving fit item: S.pd
#> ℹ saving fit item: S0
#> ℹ saving fit item: Sper
#> ℹ saving fit item: aqHi
#> ℹ saving fit item: aqLow
#> ℹ saving fit item: aqn
#> ℹ saving fit item: censInformation
#> ℹ saving fit item: cholR
#> ℹ saving fit item: cholS
#> ℹ saving fit item: conditionNumberCor
#> ℹ saving fit item: conditionNumberCov
#> ℹ saving fit item: convergence
#> ℹ saving fit item: cov
#> ℹ saving fit item: covList
#> ℹ saving fit item: covLvl
#> ℹ saving fit item: covMethod
#> ℹ saving fit item: covOptions
#> ℹ saving fit item: covR
#> ℹ saving fit item: covRS
#> ℹ saving fit item: covS
#> ℹ saving fit item: eigenCor
#> ℹ saving fit item: eigenCov
#> ℹ saving fit item: eigenVecCor
#> ℹ saving fit item: eigenVecCov
#> ℹ saving fit item: est
#> ℹ saving fit item: etaObf
#> ℹ saving fit item: extra
#> ℹ saving fit item: fixef
#> ℹ saving fit item: foceiControl0
#> ℹ saving fit item: foceiModel
#> ℹ saving fit item: fullCor
#> ℹ saving fit item: iniDf0
#> ℹ saving fit item: llikObs
#> ℹ saving fit item: logLik
#> ℹ saving fit item: message
#> ℹ saving fit item: method
#> ℹ saving fit item: mixIdx
#> ℹ saving fit item: nAGQ
#> ℹ saving fit item: nConditionalInnerHessian
#> ℹ saving fit item: nEstOmega
#> ℹ saving fit item: nInnerRerank
#> ℹ saving fit item: nTrustInner
#> ℹ saving fit item: nobs
#> ℹ saving fit item: nsub
#> ℹ saving fit item: objDf
#> ℹ saving fit item: objective
#> ℹ saving fit item: ofvType
#> ℹ saving fit item: omega
#> ℹ saving fit item: optReturn
#> ℹ saving fit item: origData
#> ℹ saving fit item: parFixed
#> ℹ saving fit item: parFixedDf
#> ℹ saving fit item: parHistData
#> ℹ saving fit item: phiC
#> ℹ saving fit item: phiH
#> ℹ saving fit item: qfirst
#> ℹ saving fit item: qw
#> ℹ saving fit item: qx
#> ℹ saving fit item: ranef
#> ℹ saving fit item: runInfo
#> ℹ saving fit item: scaleInfo
#> ℹ saving fit item: sessioninfo
#> ℹ saving fit item: shrink
#> ℹ saving fit item: table
#> ℹ saving fit item: time
#> ℹ saving fit item: tolFactor
#> ℹ saving fit item: ui
#> ℹ zipping fit files
#> ℹ loading fit from fit.zip
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> ── nlmixr² FOCEi (outer: bobyqa) ──
#> 
#>           OBJF      AIC     BIC Log-likelihood Condition#(Cov) Condition#(Cor)
#> FOCEi 116.8076 373.4073 393.587      -179.7037        538873.5        3771.305
#> 
#> ── Time (sec $time): ──
#> 
#>             setup  optimize covariance preprocess postprocess table compress
#> elapsed 0.3862331 0.4304268  0.7344415      0.048       0.045 0.079    0.001
#>             other
#> elapsed 0.2658987
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>         Est.      SE  %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka    0.472   0.208  44.1       1.60 (1.07, 2.41)     69.9       1.34 
#> tcl     1.01 0.00728 0.719       2.75 (2.71, 2.79)     27.0       4.41 
#> tv      3.46  0.0460  1.33       31.8 (29.1, 34.8)     13.9       10.4 
#> add.sd 0.695  0.0940  13.5    0.695 (0.511, 0.880)                     
#>  
#>   Covariance Type ($covMethod): r,s (full)
#>     other calculated covs (setCov()): r; s; r,s; r (full); s (full)
#>   Some strong fixed parameter correlations exist ($cor) :
#>                 cor:tcl,tka              cor:tv,tka          cor:add.sd,tka 
#>                  0.316                   0.288                   -0.177   
#>       cor:om.eta.ka,tka       cor:om.eta.cl,tka        cor:om.eta.v,tka 
#>                  0.735                  -0.163                   -0.220   
#>              cor:tv,tcl          cor:add.sd,tcl       cor:om.eta.ka,tcl 
#>                 -0.296                   -0.281                    0.260   
#>       cor:om.eta.cl,tcl        cor:om.eta.v,tcl           cor:add.sd,tv 
#>                -0.0127                    0.178                   -0.381  
#>        cor:om.eta.ka,tv        cor:om.eta.cl,tv         cor:om.eta.v,tv 
#>                  0.274                   -0.102                  -0.0694   
#>    cor:om.eta.ka,add.sd    cor:om.eta.cl,add.sd     cor:om.eta.v,add.sd 
#>                 -0.411                 -0.0705                   -0.595  
#> cor:om.eta.cl,om.eta.ka  cor:om.eta.v,om.eta.ka  cor:om.eta.v,om.eta.cl 
#>                 -0.276                    0.452                 -0.0799   
#>  
#> 
#>   No correlations in between subject variability (BSV) matrix
#>   Full BSV covariance ($omega) or correlation ($omegaR; diagonals=SDs) 
#>   Distribution stats (mean/skewness/kurtosis/p-value) available in $shrink 
#>   Information about run found ($runInfo):
#>    • gradient problems with covariance; see $scaleInfo 
#>    • last objective function was not at minimum, possible problems in optimization 
#>    • ETAs were reset to zero during optimization; (Can control by foceiControl(resetEtaP=.)) 
#>   Censoring ($censInformation): No censoring
#>   Minimization message ($message):  
#>     Normal exit from bobyqa 
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 22
#>   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 1      0     0.74  0     0.74   1.06   0     0.74   1.06   0     0.74   1.06 
#> 2 1      0.25  2.84  3.28 -0.445 -0.237  3.85 -1.01  -1.45   3.24 -0.404 -0.190
#> 3 1      0.57  6.57  5.86  0.711  0.287  6.79 -0.216 -0.310  5.81  0.763  0.278
#> # ℹ 129 more rows
#> # ℹ 10 more variables: eta.ka <dbl>, eta.cl <dbl>, eta.v <dbl>, depot <dbl>,
#> #   central <dbl>, ka <dbl>, cl <dbl>, v <dbl>, tad <dbl>, dosenum <int>
# }