Create a new C++ model object with parameters
newCppModel.RdCreates and initializes a C++ model object based on the provided parameters. This function wraps the underlying C++ model classes (LogNormalModel, LinearAbxModel, LinearAbxModel2, MixedModel) in appropriate R reference classes that expose the model's methods and properties.
Arguments
- modelParameters
List of model parameters created using functions from constructors.R, such as:
LogNormalModelParams()- Basic log-normal modelLinearAbxModel()- Linear antibiotic modelOr custom parameter lists containing:
modname: Model name ("LogNormalModel", "LinearAbxModel", "LinearAbxModel2", "MixedModel")nstates: Number of states (2 or 3)nmetro: Number of Metropolis-Hastings stepsforward: Forward simulation flagcheat: Cheat flag for debuggingInsitu: In situ parameters fromInsituParams()SurveillanceTest: Surveillance test parameters fromSurveillanceTestParams()ClinicalTest: Clinical test parameters fromClinicalTestParams()OutCol: Out-of-unit infection parameters fromOutOfUnitInfectionParams()InCol: In-unit parameters fromInUnitParams()orABXInUnitParams()Abx: Antibiotic parameters fromAbxParams()AbxRate: Antibiotic rate parameters fromAbxRateParams()
- verbose
Logical flag to print progress messages during model creation and parameter setup (default: FALSE)
Value
A reference class object wrapping the C++ model. The specific class depends
on modelParameters$modname:
CppLogNormalModel- For "LogNormalModel"CppLinearAbxModel- For "LinearAbxModel"CppLinearAbxModel2- For "LinearAbxModel2"CppMixedModel- For "MixedModel" (if exposed in C++)
All returned objects inherit from CppBasicModel and provide access to:
Properties:
InColParams- In-unit colonization parametersOutColParams- Out-of-unit colonization parametersInsituParams- In situ parametersSurveillanceTestParams- Surveillance test parametersClinicalTestParams- Clinical test parametersAbxParams- Antibiotic parameters
Methods:
logLikelihood(hist)- Calculate log likelihood for a SystemHistorygetHistoryLinkLogLikelihoods(hist)- Get individual link log likelihoodsforwardSimulate(...)- Perform forward simulationinitEpisodeHistory(...)- Initialize episode historysampleEpisodes(...)- Sample episodessetAbx(...)- Set antibiotic parameters
Details
The function uses the existing newModel C++ function to instantiate the model
and configure all parameters, then wraps it in the appropriate R reference class
based on the model type specified in modelParameters$modname.
See also
LogNormalModelParams()for creating model parametersLinearAbxModel()for linear antibiotic model parametersInsituParams(),SurveillanceTestParams(), etc. for parameter componentsnewModelExport()for extracting parameter values from a model
Examples
if (FALSE) { # \dontrun{
# Create a basic log-normal model
params <- LogNormalModelParams("LogNormalModel")
model <- newCppModel(params)
# Access model properties
inColParams <- model$InColParams
insituParams <- model$InsituParams
# Create a linear antibiotic model
params <- LinearAbxModel()
model <- newCppModel(params, verbose = TRUE)
# Get parameter values
inColParams <- model$InColParams
paramValues <- inColParams$values
# Use with a system history for likelihood calculation
# (requires data and SystemHistory object)
# ll <- model$logLikelihood(systemHistory)
} # }