Skip to contents

Save a fitted model object to a series of files

Usage

saveFit(fit, file, zip = TRUE)

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

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

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

Arguments

fit

the fitted model object

file

the base name of the files to save the fit to.

zip

Boolean indicating if the files should be zipped.

Value

nothing, called for side effects

Author

Matthew L. Fidler

Examples

# \donttest{
  if (requireNamespace("nlmixr2est", 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: .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: covLvl
#>  saving fit item: covMethod
#>  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: nEstOmega
#>  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
#>  removing unzipped fit files
#>  loading fit from fit.R
#>  
#>  
#>  
#>  
#>  
#>  
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  removing unzipped fit files
#> ── nlmix FOCEi (outer: nlminb) ──
#> 
#>          OBJF      AIC      BIC Log-likelihood Condition#(Cov) Condition#(Cor)
#> FOCEi 116.812 373.4118 393.5914      -179.7059        68.29718        9.353349
#> 
#> ── Time (sec $time): ──
#> 
#>            setup optimize covariance table    other
#> elapsed 0.003245 0.336115   0.336117 0.038 1.704523
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>         Est.     SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka    0.461  0.195 42.4       1.59 (1.08, 2.32)     70.3      1.59% 
#> tcl     1.01 0.0751 7.42       2.75 (2.37, 3.19)     26.7      4.03% 
#> tv      3.46 0.0436 1.26       31.8 (29.2, 34.6)     14.2      11.0% 
#> add.sd 0.692                               0.692                     
#>  
#>   Covariance Type ($covMethod): r,s
#>   Some strong fixed parameter correlations exist ($cor) :
#>     cor:tcl,tka  cor:tv,tka  cor:tv,tcl 
#>      0.158        0.421       0.743  
#>  
#> 
#>   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 initial estimate and covariance; see $scaleInfo 
#>    • ETAs were reset to zero during optimization; (Can control by foceiControl(resetEtaP=.)) 
#>    • initial ETAs were nudged; (can control by foceiControl(etaNudge=., etaNudge2=)) 
#>   Censoring ($censInformation): No censoring
#>   Minimization message ($message):  
#>     relative convergence (4) 
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 22
#>      ID  TIME    DV  PRED    RES   WRES IPRED   IRES  IWRES CPRED   CRES  CWRES
#>   <int> <dbl> <dbl> <dbl>  <dbl>  <dbl> <dbl>  <dbl>  <dbl> <dbl>  <dbl>  <dbl>
#> 1     1  0     0.74  0     0.74   1.07   0     0.74   1.07   0     0.74   1.07 
#> 2     1  0.25  2.84  3.26 -0.417 -0.223  3.84 -1.00  -1.45   3.21 -0.372 -0.174
#> 3     1  0.57  6.57  5.82  0.746  0.299  6.78 -0.215 -0.311  5.77  0.802  0.290
#> # ℹ 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>
# }