Bayesian individual dynamics predictions
This partial example corresponds to Bayesian individual dynamic predictions with uncertainty. This is what it does:
estimates population parameters for a model,
fixes the population parameters to the estimates,
changes the dataset for another, that can be filtered up to some landmark time,
runs the task Conditional distribution that samples sets of parameters from the individual posterior distributions,
simulates the model based on the sampled parameters with Simulx.
library("lixoftConnectors")
initializeLixoftConnectors(software = "monolix")
loadProject(projectFile = "path_to_projet_file.mlxtran")
# set pop params to estimates and fix pop params
runPopulationParameterEstimation()
setInitialEstimatesToLastEstimates()
popparams <- getPopulationParameterInformation()
popparams$method <- "FIXED"
setPopulationParameterInformation(popparams)
# here the data can be modified in the project to take into account data until landmark time
filtereddatfile <- "path to data filtered up to landmark time.csv"
BaseData <- getData()
setData(filtereddatfile, BaseData$headerTypes, BaseData$observationTypes)
# set MCMC settings: min number iter=1000, relative interval width=1, number of param per indiv=200
# this is to sample 200 parameters from 1000 iterations. Samples are uniformly spread on the iterations.
CondDistSettings <- getConditionalDistributionSamplingSettings()
setConditionalDistributionSamplingSettings(nbminiterations=500, ratio=1, nbsimulatedparameters=200)
# run SAEM and conditional distribution
runPopulationParameterEstimation() # mandatory before other tasks, but nb of iterations is null as all parameters are fixed
runConditionalDistributionSampling() # this is sampling from the posterior distribution for each individual
simparams <- getSimulatedIndividualParameters()
simparams$id <- row.names(simparams) # replace id by rank of {rep, id}
simparams$rep <- NULL
write.csv(simparams, file="table_simulated_parameters.csv", row.names = F)
# simulate based on simulated parameters using Simulx
initializeLixoftConnectors(software = "simulx", force=TRUE)
importMonolixProject(projectFile = "path_to_projet_file.mlxtran")
defineIndividualElement(name="simulatedParameters", element="table_simulated_parameters.csv")
setGroupElement(group = "simulationGroup1", elements = c("simulatedParameters"))
setGroupSize(group = "simulationGroup1", size = nrow(simparams))
runSimulation()
simresults <- getSimulationResults()