% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dpit_2pm.R
\name{dpit_2pm}
\alias{dpit_2pm}
\title{Residuals for regression models with two-part outcomes}
\usage{
dpit_2pm(model0, model1, y, part0, part1, plot=TRUE, scale = "normal",
 line_args= list(), ...)
}
\arguments{
\item{model0}{Model object for 0 outcomes (e.g., logistic regression)}

\item{model1}{Model object for the continuous part (gamma regression)}

\item{y}{Semicontinuous outcomes.}

\item{part0}{Alternative argument to \code{model0}. One can supply the sequence of probabilities \eqn{P(Y_i=0),~i=1,\ldots,n}.}

\item{part1}{Alternative argument to \code{model1}. One can fit a regression model on the positive data and supply their probability integral transform. Note that the length of \code{part1} is the number of positive values in \code{y} and can be shorter than \code{part0}.}

\item{plot}{A logical value indicating whether or not to return QQ-plot}

\item{scale}{You can choose the scale of the residuals among \code{normal} and \code{uniform}. The default scale is \code{normal}.}

\item{line_args}{A named list of graphical parameters passed to
\code{graphics::abline()} to modify the reference (red) 45° line
in the QQ plot. If left empty, a default red dashed line is drawn.}

\item{...}{Additional graphical arguments passed to
\code{stats::qqplot()} for customizing the QQ plot (e.g., \code{pch},
\code{col}, \code{cex}, \code{xlab}, \code{ylab}).}
}
\value{
Residuals. If plot=TRUE, also produces a QQ plot.
}
\description{
Calculates DPIT residuals with model for semi-continuous outcomes.
\code{dpit_2pm} can be used either with \code{model0} and \code{model1} or with \code{part0} and \code{part1} as arguments.
}
\details{
For formulation details on semicontinuous outcomes, see \code{\link{dpit}}.

In two-part models, the probability of zero can be modeled using a logistic regression, \code{model0},
while the positive observations can be modeled using a gamma regression, \code{model1.}
Users can choose to use different models and supply the resulting probabilities of zero and probability integral transforms.
\code{part0} should be the sequence of fitted probabilities of zeros \eqn{\hat{p}_0(\mathbf{X}_i) ,~i=1,\ldots,n}.
\code{part1} should be the probability integral transform of the positive part \eqn{\hat{G}(Y_i|\mathbf{X}_i)}.
Note that the length of \code{part1} is the number of positive values in \code{y} and can be shorter than \code{part0}.
}
\examples{
library(MASS)
n <- 500
beta10 <- 1
beta11 <- -2
beta12 <- -1
beta13 <- -1
beta14 <- -1
beta15 <- -2
x11 <- rnorm(n)
x12 <- rbinom(n, size = 1, prob = 0.4)

p1 <- 1 / (1 + exp(-(beta10 + x11 * beta11 + x12 * beta12)))
lambda1 <- exp(beta13 + beta14 * x11 + beta15 * x12)
y2 <- rgamma(n, scale = lambda1 / 2, shape = 2)
y <- rep(0, n)
u <- runif(n, 0, 1)
ind1 <- which(u >= p1)
y[ind1] <- y2[ind1]

# models as input
mgamma <- glm(y[ind1] ~ x11[ind1] + x12[ind1], family = Gamma(link = "log"))
m10 <- glm(y == 0 ~ x12 + x11, family = binomial(link = "logit"))
resid.model <- dpit_2pm(model0 = m10, model1 = mgamma, y = y)

# PIT as input
cdfgamma <- pgamma(y[ind1],
  scale = mgamma$fitted.values * gamma.dispersion(mgamma),
  shape = 1 / gamma.dispersion(mgamma)
)
p1f <- m10$fitted.values
resid.pit <- dpit_2pm(y = y, part0 = p1f, part1 = cdfgamma)
}
