% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mixed_effect_bpval.R
\name{glme_bpv}
\alias{glme_bpv}
\title{Pearson Statistic BPval}
\usage{
glme_bpv(object)
}
\arguments{
\item{object}{Mixed effect GLM from package rstanarm}
}
\value{
A list containing the bayesian P-value, and a plot of \eqn{T_{obs}} vs \eqn{T_{pred}}
}
\description{
Calculates bayesian P-value based on pearson statistic for rstanrm mixed models
}
\details{
Returns a bayesian P-value based on model fit. The statistic
is calculated by fitting predicted residuals vs and fitted values, and
fitting observed residuals vs fitted values. For both of these relationships,
a loess curve is fit and the loess-fit predicted residuals. The sum of
squares of these loess-fit predicted residuals is compared across multiple
posterior draws. In particular:

Define \eqn{y_i^{(d)}} as the \eqn{i}th posterior predicted value from the \eqn{d}th posterior draw of \eqn{\theta}.
Similarly, define \eqn{\mu_i^{(d)} = E[y_i|\theta^{(d)}]} as the expected value of \eqn{y_i} under the \eqn{d}th posterior draw of $\theta$.

Consider the \eqn{n} observed residuals and the \eqn{n} predicted residuals:

\deqn{r_{i, obs}^{(d)} = y_i - \mu_i^{(d)}}
\deqn{r_{i, pred}^{(d)} = y_i^{(d)} - \mu_i^{(d)} }

If we fit two loess curves:

\deqn{\text{LOESS}(\mathbf{r}_{obs}^{(d)}, \boldsymbol{\mu}^{(d)})}
\deqn{\text{LOESS}(\mathbf{r}_{pred}^{(d)}, \boldsymbol{\mu}^{(d)})}

These two models give rise to the predicted residuals: \eqn{\hat{\mathbf{r}}_{obs}^{(d)}}
and \eqn{\hat{\mathbf{r}}_{pred}^{(d)}}. Define the statistics

\deqn{T_{obs}^{(d)} = \frac{1}{n}\sum_{i = 1}^n \left(\hat{r}_{obs}^{(d)}\right)^2}
\deqn{T_{pred}^{(d)} = \frac{1}{n}\sum_{i = 1}^n \left(\hat{r}_{pred}^{(d)}\right)^2}

The bayesian p-value is given by

\deqn{\frac{1}{D}\sum_{d = 1}^{D} I(T_{pred}^{(d)} > T_{obs}^{(d)})}
}
