% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sg-converter.R
\name{sg_converter}
\alias{sg_converter}
\title{Convert Monolix project output to R objects}
\usage{
sg_converter(folder_path, proj_name, save_file = FALSE)
}
\arguments{
\item{folder_path}{Character string. Path to the directory containing Monolix project files.}

\item{proj_name}{Character string. Name of the Monolix project (without file extension).}

\item{save_file}{Logical. If \code{TRUE}, saves \code{GCO} and \code{GFO} JSON files
to \code{folder_path} with names \code{<proj_name>_GCO.json} and \code{<proj_name>_GFO.json},
and also saves two RData files: \code{<proj_name>_GCO.RData} (object \code{gco})
and \code{<proj_name>_GFO.RData} (object \code{gfo}).}
}
\value{
Returns a list with the following components:
\itemize{
\item \code{GFO}: SimuRg generalized fit object output object with:
\itemize{
\item \code{SDTAB}: A tibble containing data used for fitting
\item \code{SUMTAB}: A tibble with parameter summary statistics containing
\item \code{SIGMAMAT}: Residual variability matrix
\item \code{OMEGAMAT}: Inter-individual variability matrix
\item \code{OCCMAT}: Inter-occasion variability matrix (NA if not present)
\item \code{EVTAB}: A tibble with event information
\item \code{PATAB}: A tibble with individual parameter estimates
\item \code{COTAB}: A tibble with continuous covariates
\item \code{CATAB}: A tibble with categorical covariates
\item \code{REGTAB}: Regression parameters (empty data.frame if not present)
\item \code{OFV}: A tibble with objective function values
\item \code{COVMAT}: Variance-covariance matrix of parameter estimates
\item \code{CORRMAT}: Correlation matrix of parameter estimates
\item \code{OPTIONS}: Model options (NULL if not present)
\item \code{PROJNAME}: Project name
}
\item \code{GCO}: SimuRg generalized control object parsed from the mlxtran project with:
\itemize{
\item \code{headers}: List of dataset column descriptors (\code{name}, \code{use}, \code{type})
\item \code{data}: Path to source data file
\item \code{model}: Path to model file
\item \code{task_opt}: Task options placeholder (empty object)
\item \code{covs}: Covariate names detected
\item \code{project_name}: Project name
\item \code{theta}: List of population parameter definitions (\code{NAME}, \code{INIT}, \code{EST}, \code{TRANS})
\item \code{ruv}: Residual error model definition (\code{YNAME}, \code{DVID}, \code{TRANS}, \code{PRED}, \code{ERR}, \code{INIT}, \code{EST})
\item \code{re}: Between-subject variability matrices (\code{init}, \code{est})
\item \code{occ}: Between-occasion variability matrices (\code{init}, \code{est})
\item \code{modelText}: Text content of the model file
}
}
}
\description{
Reads and parses Monolix project output files (.mlxtran and associated data files)
into a structured list of SimuRg objects including parameter estimates, individual predictions,
residuals, and diagnostic information.
}
\details{
This function serves as a bridge between Monolix output and R by parsing the .mlxtran file
and associated data files to create a comprehensive R object containing all relevant model
outputs. This facilitates further analysis, visualization, and reporting in R.

The function automatically detects and imports various components of Monolix output
including population parameters, individual parameters, covariates, and diagnostic
metrics.

If \code{save_file = TRUE}, the function additionally writes \code{GCO} and \code{GFO}
JSON files and \code{.RData} files to \code{folder_path}.
}
\examples{
\donttest{
library(stringr)
# Convert Monolix project results
test_folder <- system.file("extdata", "Monolix_objects", package = "SimuRg")
if (substr(test_folder, nchar(test_folder), nchar(test_folder)) != "/")
  test_folder <- str_c(test_folder, "/")
pro_name <- "proj-solo"
result <- sg_converter(folder_path = test_folder, proj_name = pro_name)
# save(results, file = "./models/simurg_object/Warfarin_PK.RData")
# Access individual predictions
head(result$GFO$SDTAB)

# View parameter estimates
print(result$GFO$SUMTAB)

# Check objective function value
print(result$GFO$OFV)
}
}
