Refit with Saved Parameters

Overview

This vignette walks through using a text file of previously fit model parameters to use in the bdotsRefit function. This is convenient if you have already gone through the refitting process and would like to save/load the refitted parameters in a new session.

To demonstate this process, we start with fitting a set of curves to our data

library(bdots)

fit <- bdotsFit(data = cohort_unrelated,
                subject = "Subject",
                time = "Time",
                y = "Fixations",
                group = c("Group", "LookType"),
                curveType = doubleGauss(concave = TRUE),
                cor = TRUE,
                numRefits = 2,
                cores = 2,
                verbose = FALSE)

refit <- bdotsRefit(fit, quickRefit = TRUE, fitCode = 5)

From this, we can create an appropriate data.table that can be used in a later session

parDT <- coefWriteout(refit)
head(parDT)
#>    Subject  Group LookType       mu        ht     sig1     sig2       base1
#>     <char> <char>   <char>    <num>     <num>    <num>    <num>       <num>
#> 1:       1     50   Cohort 417.6899 0.1986711 145.5628 323.1882  0.01586359
#> 2:       1     65   Cohort 636.8447 0.2632815 306.2330 214.9787 -0.02154794
#> 3:       2     50   Cohort 647.5295 0.2547779 496.6745 256.4257 -0.18223562
#> 4:       2     65   Cohort 734.1526 0.2585742 405.6348 240.2926 -0.05751246
#> 5:       3     50   Cohort 501.1948 0.2258572 398.7759 158.6752 -0.16159473
#> 6:       3     65   Cohort 460.7152 0.3067659 382.7323 166.0833 -0.24330894
#>         base2
#>         <num>
#> 1: 0.03412371
#> 2: 0.02858644
#> 3: 0.01217570
#> 4: 0.03455280
#> 5: 0.02529158
#> 6: 0.03992168

It’s important that columns are included that match the unique identifying columns in our bdotsObj, and that the parameters match the coefficients used from bdotsFit

## Subject, Group, and LookType
head(refit)
#>    Subject  Group LookType          fit        R2    AR1 fitCode
#>     <char> <char>   <char>       <AsIs>     <num> <lgcl>   <int>
#> 1:       1     50   Cohort list(), .... 0.9701367  FALSE       3
#> 2:       1     65   Cohort list(), .... 0.9805103  FALSE       3
#> 3:       2     50   Cohort list(), .... 0.9813076  FALSE       3
#> 4:       2     65   Cohort list(), .... 0.9701257  FALSE       3
#> 5:       3     50   Cohort list(), .... 0.9765418  FALSE       3
#> 6:       3     65   Cohort list(), .... 0.9534922  FALSE       3

## doubleGauss pars
colnames(coef(refit))
#> [1] "mu"    "ht"    "sig1"  "sig2"  "base1" "base2"

We can save our parameter data.table for later use, or read in any other appropriately formatted data.frame

## Save this for later using data.table::fwrite
fwrite(parDT, file = "mypars.csv")
parDT <- fread("mypars.csv")

Once we have this, we can pass it as an argument to the bdotsRefit function. Doing so will ignore the remaining arguments

new_refit <- bdotsRefit(refit, paramDT = parDT)

We end up with a bdotsObj that matches what we had previously. As seeds have not yet been implemented, the resulting parameters may not be exact. It will, however, assist with not having to go through the entire refitting process again manually (although, there is always the option to save the entire object with save(refit, file = "refit.RData))

head(new_refit)
#>    Subject  Group         LookType          fit        R2    AR1 fitCode
#>     <char> <char>           <char>       <AsIs>     <num> <lgcl>   <int>
#> 1:       1     50           Cohort list(cor.... 0.9701367   TRUE       0
#> 2:       1     50 Unrelated_Cohort list(cor.... 0.9793524   TRUE       0
#> 3:       1     65           Cohort list(cor.... 0.9805103   TRUE       0
#> 4:       1     65 Unrelated_Cohort list(cor.... 0.8742477   TRUE       1
#> 5:       2     50           Cohort list(cor.... 0.9813076   TRUE       0
#> 6:       2     50 Unrelated_Cohort list(cor.... 0.9561882   TRUE       0