Skip to content

Commit b57cd20

Browse files
committed
Update internal documentation for new features
1 parent bc2fe36 commit b57cd20

10 files changed

+166
-14
lines changed

R/FIPS_formula_interface.R

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,29 @@ validate_formula <- function(.FIPS_sim, model_formula) {
44
NULL
55
}
66

7+
8+
#' get_bmm_model_frame
9+
#'
10+
#' @param .FIPS_sim A FIPS_Simulation object
11+
#' @param model_formula A formula describing how the time-varying processes predictors should be calculated for the predicted output.
12+
#'
13+
#' @return Minimal dataframe with only requird columns for computation
714
get_bmm_model_frame <- function(.FIPS_sim, model_formula) {
815
validated_labs = attr(terms(model_formula), "term.labels")
916
validated_labs = validated_labs[!grepl("I\\(", validated_labs)]
1017
model_frame = data.frame(.FIPS_sim[,c(validated_labs)])
1118
return(model_frame)
1219
}
1320

21+
#' process_bmm_formula
22+
#'
23+
#' The pvec is required to ensure it is contained in the environment for expression evaluation.
24+
#'
25+
#' @param .FIPS_sim A FIPS_Simulation object
26+
#' @param model_formula A formula describing how the time-varying processes predictors should be calculated for the predicted output.
27+
#' @param pvec A required pvec argument for the .FIPS_sim
28+
#'
29+
#' @return Minimal dataframe with only requird columns for computation
1430
process_bmm_formula <- function(.FIPS_sim, model_formula, pvec) {
1531
validate_formula(.FIPS_sim, model_formula)
1632
# Get a reduced .FIPS_sim with only required columns
@@ -27,13 +43,15 @@ process_bmm_formula <- function(.FIPS_sim, model_formula, pvec) {
2743
return(.FIPS_sim)
2844
}
2945

30-
# Used for adding vectors to .FIPS_sim
46+
# Used for adding vectors to .FIPS_sim object (i..e, column binding)
47+
# and ensures attributes as set.
3148
add_formula_vector <- function(.FIPS_sim, pred_vector, pred_name) {
3249
.FIPS_sim[,pred_name] = pred_vector
3350
attr(.FIPS_sim, "pred_cols") = c(attr(.FIPS_sim, "pred_cols"), pred_name)
3451
return(.FIPS_sim)
3552
}
3653

54+
# Set the pred_stat object
3755
set_pred_stat <- function(.FIPS_sim, pred_stat_name) {
3856
attr(.FIPS_sim, "pred_stat") = pred_stat_name
3957
return(.FIPS_sim)

R/FIPS_simulate.R

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@
44
#' It will dispatch to the selected model simulation type and then return the df with
55
#' the fitted model columns added on as a `FIPS_simulation` object.
66
#'
7+
#' If the formula argument is omitted, then default prediction values will be returned:
8+
#' KSS and alertness for TPM, and fatigue (i.e., lapses) for unified.
9+
#'
710
#'
811
#' @param FIPS_df A valid FIPS_df series that has not already been modelled
912
#' @param modeltype String: either `"TPM"` (Three Process Model) or `"unified"`.
1013
#' @param pvec Parameter vector (named list), see default pvecs for guidance.
11-
#' @param model_formula A formula describing how the time-varying processes predictors should be calculated for the predicted output. See details.
12-
#'
14+
#' @param model_formula An optional formula describing how the time-varying processes predictors should be calculated for the predicted output. See details.
15+
#'
16+
#' @details
17+
#'
18+
#' ### Formula Argument
19+
#'
20+
#' - The formula argument takes the form of an R formula expression (e.g., `y ~ c + s`).
21+
#' - The term of the left-hand side (e.g., `y`) defines the variable name
22+
#' - The term(s) on the right-hand side define how the variable is computed
23+
#' - All variables must be defined in your enviornment or in the FIPS_simulation output (e.g., `s, c, l, w` for "TPM").
24+
#' - Parameter vector and other variable arguments must be placed in `I(expression)` format. For example,
25+
#' `fatigue ~ s + c + I(pvec[["KSS_beta"]])`.
26+
#'
1327
#' @md
1428
#' @return a FIPS_simulation object
1529
#' @export

R/simulation_threeprocessmodel.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,10 @@ TPM_append_model_cols <- function(.FIPS_df) {
219219

220220
#' TPM_add_KSS
221221
#'
222-
#' @param .FIPS_sim
222+
#' Adds the KSS to a TPM FIPS_simulation. Will return error if FIPS_simulation not a TPM.
223223
#'
224-
#' @return
225-
#' @export
224+
#' @param .FIPS_sim a FIPS_simulation on the TPM
226225
#'
227-
#' @examples
228226
TPM_get_KSS_vector <- function(.FIPS_sim) {
229227

230228
# Make sure we are operating on a TPM model
@@ -248,6 +246,14 @@ TPM_get_KSS_vector <- function(.FIPS_sim) {
248246
return(KSS_vector)
249247
}
250248

249+
#' TPM Simulation Dispatcher
250+
#'
251+
#' Constructor/dispatcher for TPM model simulations.
252+
#'
253+
#' @param dat input dataframe (ensure this is in FIPS format)
254+
#' @param pvec a vector of default parameters
255+
#' @param model_formula A formula expression object of desired model caluclation
256+
#'
251257
TPM_simulation_dispatch <- function(dat, pvec, model_formula) {
252258
# check pvec for any problems, and whether parameters are the default
253259
TPM_check_pvec(pvec)
@@ -256,12 +262,12 @@ TPM_simulation_dispatch <- function(dat, pvec, model_formula) {
256262
dat = TPM_append_model_cols(dat)
257263
# Run the unified main simulation loop on dat
258264
dat = TPM_simulate(pvec, dat)
259-
# Assign as FIPS_simulation class
265+
# Assign as FIPS_simulation class
260266
dat = FIPS_simulation(dat, modeltype = "TPM", pvec = pvec, pred_stat = "alertness", pred_cols = TPM_cols, model_formula = model_formula)
261267
# Add any required formula calculations
262268
if (is.null(model_formula)) {
263269
dat = add_formula_vector(.FIPS_sim = dat, pred_vector = TPM_get_KSS_vector(dat), pred_name = "KSS")
264-
dat = process_bmm_formula(dat, alertness ~ s + c + u, pvec)
270+
dat = process_bmm_formula(dat, alertness ~ s + c + u, pvec)
265271
}
266272
if (!is.null(model_formula)) {
267273
dat = process_bmm_formula(dat, model_formula, pvec)

R/simulation_unifiedfatiguemodel.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,26 @@ unified_append_model_cols <- function(.FIPS_df) {
158158
return(.FIPS_df)
159159
}
160160

161+
162+
#' Unified Simulation Dispatcher
163+
#'
164+
#' Constructor/dispatcher for Unified model simulations.
165+
#'
166+
#' @param dat input dataframe (ensure this is a FIPS_df)
167+
#' @param pvec a vector of default parameters, see [unified_pvec]
168+
#' @param model_formula A formula expression object of desire model caluclation
161169
unified_simulation_dispatch <- function(dat, pvec, model_formula) {
162170
# check pvec
163171
unified_check_pvec(pvec)
164172
# Add the unified model columns
165173
dat = unified_append_model_cols(dat)
166174
# Run the unified main simulation loop on dat
167175
dat = unified_simulate(pvec, dat)
168-
# Assign as FIPS_simulation class
176+
# Assign as FIPS_simulation class
169177
dat = FIPS_simulation(dat, modeltype = "unified", pvec = pvec, pred_stat = "fatigue", pred_cols = unified_cols)
170178
# Add any required formula calculations
171179
if (is.null(model_formula)) {
172-
dat = process_bmm_formula(dat, fatigue ~ s + I(pvec["kappa"]) * c, pvec)
180+
dat = process_bmm_formula(dat, fatigue ~ s + I(pvec["kappa"]) * c, pvec)
173181
}
174182
if (!is.null(model_formula)) {
175183
dat = process_bmm_formula(dat, model_formula, pvec)
@@ -202,7 +210,7 @@ unified_simulation_dispatch <- function(dat, pvec, model_formula) {
202210
#' @return simulated dataset complete
203211
#' @export
204212
unified_simulate <- function(pvec, dat) {
205-
213+
206214
# Initialise S and L
207215
if (dat$wake_status[1]) {
208216
s_at_wake = pvec["S0"]
@@ -242,5 +250,5 @@ unified_simulate <- function(pvec, dat) {
242250
}
243251

244252
return(dat)
245-
253+
246254
}

man/FIPS_simulate.Rd

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/TPM_get_KSS_vector.Rd

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/TPM_simulation_dispatch.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_bmm_model_frame.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/process_bmm_formula.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/unified_simulation_dispatch.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)