\name{gc_continuous}
\alias{gc_continuous}
\title{
G-Computation to Estimate a Marginal Effect with a Continuous Outcome
}
\description{
This function computes G-computation (GC) with different working models or algorithms (Q-models) for a continuous outcome and a 2-class exposure/treatment.
}
\usage{
gc_continuous(formula, data, group, effect="ATE", model,
            param.tune=NULL, cv=30, boot.type="bcv", boot.number=500,
            boot.tune=FALSE, progress=TRUE, seed=NULL, boot.mi=FALSE, m=5, ...)
}

\arguments{
  \item{formula}{A regression formula related to the Q-model with the variable \code{group} among the predictors.}
  \item{data}{A data frame in which to look for the variables related to the outcome, the studied (\code{group}) and the predictors included in the previous model.}
  \item{group}{The name of the variable related to the exposure/treatment. This variable shall have only two modalities encoded 0 for the untreated/unexposed subjects and 1 for the treated/exposed ones.}
   \item{effect}{The type of the marginal effect to be estimated. Three types are possible: "ATE" (by default), "ATT" and "ATU". See details.}   
   \item{model}{The modelling method used to create the Q-model. Current implemented methods are: "all", "lasso", "ridge", "elasticnet", "aic" and "bic". See details.} 
   \item{param.tune}{An optional argument to specify the tuning parameter(s) for the previous  modelling method. If \code{NULL} (the default), the tuning parameter(s) is(are) estimated by \code{cv}-fold cross-validation. Otherwise, the user can propose a tuning grid. See details.}
    \item{cv}{The number of splits for cross-validation. The default value is 30.}
    \item{boot.type}{The type of bootstrap to use. Two types are possible: "bcv" for bootstrap cross-validation (by default) and "boot" usual bootstrap. See details.}
    \item{boot.number}{The number of bootstrap resamples. The default value is 500.}
    \item{boot.tune}{A logical value to determine whether the tuning parameter(s) should be estimated inside of each bootstrap iteration. See details.}
    \item{progress}{A logical value to print a progress bar. The default is \code{TRUE}}
    \item{seed}{A random seed to ensure reproducibility during the cv process. If \code{NULL}, a seed is randomly assigned.}
    \item{boot.mi}{A logical value to apply multiple imputation using the \code{\link[mice]{mice}} package. See details.}
    \item{m}{Number of imputations to perform if boot.mi is \code{TRUE}.}
  \item{...}{Additional arguments to be passed directly to the \code{\link[mice]{mice}} function for customizing the multiple imputation process (e.g., \code{method}, \code{maxit}, \code{diagnostics}).}
 }

\details{
The option \code{methods="ATE"} corresponds to the Average Treatment effect on the Entire population, i.e. the marginal effect if the entire sample were treated versus untreated. The "ATT" modality allows the estimation of the Average Treatment effect on the Treated, i.e. the marginal effect if the treated subjects (\code{group = 1}) would have been untreated. The "ATU" modality allows the estimation of the Average Treatment effect on the Untreated, i.e. the marginal effect if the untreated subjects (\code{group = 0}) would have been treated.

Several modelling methods can be used for the Q-model estimation:
\tabular{lll}{
\code{"all"} \tab A linear regression,  all the covariates in the formula being used.\cr
\code{"lasso"} \tab L1 regularized linear regression allowing predictors' selection.\cr
\code{"ridge"} \tab L2 regularized linear regression allowing highly correlated predictors.\cr
\code{"elasticnet"} \tab A linear regression which combines both L1 and L2 regularizations.\cr
\code{"aic"} \tab A linear regression with a AIC-based forward selection.\cr
\code{"bic"} \tab A linear regression with a BIC-based forward selection.
}

The \code{param.tune} argument allows users to specify tuning parameters of penalized regression. If \code{NULL} (the default), the tuning parameters of each algorithm are estimated by cv-fold cross-validation  and the default grid of the \code{glmnet} package is used. Otherwise, the user can propose a specific grid. For "lasso" and "ridge" penalizations, it should be a vector representing the lambda penalization parameter. For "elasticnet", it should be a list or a vector of length 2, containing lambda (penalization parameter) and alpha (mixing parameter between L1 and L2 regularizations) values. The alpha value typically ranges from 0 to 1. The user may propose a single value of each tuning parameter if she/he aims to define her/his own penalty.

The \code{boot.tune} argument is logical value which determines whether the tuning parameter should be estimated inside of each bootstrap iteration. If \code{FALSE} (the default), the tuning parameter will be estimated once on the complete dataset.

The \code{boot.type} argument controls how bootstrap estimates are computed. With \code{boot.type = "boot"}, each iteration fits the Q-model on a sampled dataset and predicts on the same patients. With \code{boot.type = "bcv"}, the Q-model is fitted on the sampled patients, and predictions are made on patients not included in that sample.

If \code{boot.mi = TRUE}, multiple imputation is considered by using the MI-BOOT approach proposed by Schomaker & Heumann (2018). The dataset is first imputed using the \code{\link[mice]{mice}} function to create \code{m} complete datasets. The bootstrap samples are then generated from each imputed dataset. The Q-model and the G-computation is performed for each \code{m} x \code{boot.number} samples, and all runs are finally concatenated.
}

\value{
\item{qmodel.fit}{The fitted Q-model.}
\item{predictions}{The outcome predictions obtained on the complete dataset.}
\item{tuning.parameters}{The estimated tuning parameters for the Q-model. For "aic" and "bic" methods, this represents the final model.}
\item{data}{The data frame with individual with no missing data in the formula parameters.}
\item{formula}{The formula provided by the user.}
\item{model}{The method used for the Q-model.}
\item{cv}{The number of splits used for cross-validation.}
\item{penalty.factor}{The penalty factors used for the penalized regression. The variable \code{group} has a penalty factor of 0 (no penalization) and 1 for the others.}
\item{missing}{The number of observations that were removed from the original dataset due to missing values.}
\item{boot.number}{The total number of bootstrap resamples.}
\item{boot.type}{The type of bootstrap.}
\item{group}{A character string specifying the name of the variable related to the exposure or treatment.}
\item{n}{The sample size of the dataset after missing data removal (if \code{boot.mi = FALSE}).}
\item{adjusted.results}{A data frame containing the adjusted results for each bootstrap sample: \code{m1} (mean experimental), \code{m0} (mean control), \code{delta} (difference), and \code{ratio} (mean ratio).}
\item{unadjusted.results}{A data frame containing the unadjusted results for each bootstrap sample: \code{m1} (mean experimental), \code{m0} (mean control), \code{delta} (difference), and \code{ratio} (mean ratio).}
\item{call}{The function call that generated the \code{gccontinuous} object.}
\item{m}{The number of multiple imputations performed (only present if \code{mi.boot = TRUE}).}
\item{initial.data}{The original dataset provided by the user, before any imputation (only present if \code{mi.boot = TRUE}).}
\item{nimput}{The number of observations with missing values that were removed from the dataset prior to imputation (only present if \code{mi.boot = TRUE}).}
\item{seed}{The random seed used.}
}

\references{
Joe de Keizer et al. G-computation for increasing performances of clinical trials with individual randomization and binary response. ArXiv 2024-11. <doi:10.48550/arXiv.2411.10089>.

Schomaker M, Heumann C. Bootstrap inference when using multiple imputation. Statistics in medicine. 2018;37(14):2252-2266. <doi:10.1002/sim.7654>.}

\examples{
data("dataPROPHYVAP")

.f <- formula(HYPOTENSION ~ GROUP * AGE + SEX + ALCOHOL + BMI + DIABETES + GLASGOW + INJURY)

### In practice use larger values for cv and boot.number
### We set boot.number and cv at 10 for speed in CRAN checks
### cv=30 and boot.number=1000 are more appropriate values
gc1 <- gc_continuous(formula=.f, model="lasso", data=dataPROPHYVAP,
              group="GROUP", param.tune=NULL, cv=10, boot.type="bcv",
              boot.number=10, effect="ATE", boot.tune=TRUE)

summary(gc1)
}

\keyword{G-computation}
\keyword{Continuous outcome}