# In zrmacc/BinReg: BinReg

knitr::opts_chunk$set(echo=T, warning=F, message=F, cache=F, results='hold');  ## Contents # Introduction This package provides implementations of regression models for a binary outcome. Throughout denote the outcome$y_{i}\in{0,1}$, the covariates$x_{i}\in\mathbb{R}^{p}$, and the linear predictor$\eta_{i} = x_{i}'\beta$. # Logistic ## Model In logistic regression, the latent variable$z_{i}$follows a logistic distribution with center$\eta_{i}$and unit scale: $$z_{i}|x_{i} \sim \text{Logistic}\big(\eta_{i},1) \ y_{i} = I[z_{i}>0]$$ ## Estimation Below, data are simulated for$n=10^{3}$subjects. The model matrix X includes an intercept and four standard normal covariates. The function rBinReg is provided for simulating from binary regression models. The function Fit.BinReg with model="logistic" specifies a logistic model. set.seed(101); library(BinReg); # Subjects n = 1e3; # Design matrix X = cbind(1,matrix(rnorm(n=4*n),nrow=n)); # Regression coefficient b = c(1,-1,2,-1,0); # Logistic outcome y = rBinReg(X,b,model="logistic"); # Estimate regression parameters M = Fit.BinReg(y=y,X=X,model="logistic"); show(M);  ## Inference Wald tests for individual coefficients are stored in M@Coefficients and displayed using the show method. The function Score.BinReg performs score tests on subsets of the regression coefficients. The test is specified using a logical vector L with as many elements as columns in the model matrix X. An element of L is set to TRUE if the regression coefficient for that column of X is fixed under$H_{0}$. An element of L is set to FALSE if the regression coefficient for that column requires estimation under$H_{0}$. At least one element of L must be TRUE (i.e. a test must be specified) and at least one element of L must be FALSE (i.e. a null model must be estimable). Below, various hypothses are tested on the example data. The first is an overall test that the coefficients for all covariates, other than the intercept, are zero. The null hypothesis is$H_{0}:\beta_{1}=\beta_{2}=\beta_{3}=\beta_{4}=0$, which is false. The second is an individual test that the coefficient for the fourth covariate is zero. The null hypothesis is$H_{0}:\beta_{4}=0$, which is true. The third is a joint test that the coefficient for the second covariate is zero, and the coefficient for the fourth covariate is two. The null hypothesis is$H_{0}:\beta_{2}=0,\beta_{4}=2$, which if false. The fourth is a joint test that the coefficients for the first and third covariates are equal to negative one. The null hypothesis is$H_{0}:\beta_{1}=\beta_{3}=-1$, which is true. All models include an intercept$\beta_{0}$, since in each case L[1]=FALSE. cat("Test of b1=b2=b3=b4=0:\n"); Score.BinReg(y=y,X=X,L=c(F,T,T,T,T),model="logistic",report=F); cat("\n"); cat("Test of b4=0:\n"); Score.BinReg(y=y,X=X,L=c(F,F,F,F,T),model="logistic",report=F); cat("\n"); cat("Test of b2=0, b4=2:\n"); Score.BinReg(y=y,X=X,L=c(F,F,T,F,T),b10=c(0,2),model="logistic",report=F); cat("\n"); cat("Test of b1=b3=-1:\n"); Score.BinReg(y=y,X=X,L=c(F,T,F,T,F),b10=c(-1,-1),model="logistic",report=F); cat("\n");  # Probit ## Model In probit regression, the latent variable$z_{i}$follows a normal distribution with center$\eta_{i}$and unit scale: $$z_{i}|x_{i} \sim N\big(\eta_{i},1) \ y_{i} = I[z_{i}>0]$$ ## Estimation The function Fit.BinReg with model="probit" specifies a probit model. # Probit outcome y = rBinReg(X,b,model="probit"); # Estimate regression parameters M = Fit.BinReg(y=y,X=X,model="probit"); show(M);  ## Inference The same hypotheses considered previously are tested for the probit model. cat("Test of b1=b2=b3=b4=0:\n"); Score.BinReg(y=y,X=X,L=c(F,T,T,T,T),model="probit",report=F); cat("\n"); cat("Test of b4=0:\n"); Score.BinReg(y=y,X=X,L=c(F,F,F,F,T),model="probit",report=F); cat("\n"); cat("Test of b2=0, b4=2:\n"); Score.BinReg(y=y,X=X,L=c(F,F,T,F,T),b10=c(0,2),model="probit",report=F); cat("\n"); cat("Test of b1=b3=-1:\n"); Score.BinReg(y=y,X=X,L=c(F,T,F,T,F),b10=c(-1,-1),model="probit",report=F); cat("\n");  # Robit ## Model In robit regression, the latent variable$z_{i}$follows a$t_{\nu}$distribution with center$\eta_{i}$, unit scale, and specified degrees of freedom$\nu\$:

$$z_{i}|x_{i} \sim t_{\nu}(\eta_{i}) \ y_{i} = I[z_{i}>0]$$

## Estimation

The function Fit.BinReg with model="robit" specifies a robit model. Note that the degrees of freedom requires specification. The robit model with df=7 is similar to the logistic model.

# Degrees of freedom
df = 7;
# Robit outcome
y = rBinReg(X,b,model="robit",df=df);
# Recover regression parameters
M = Fit.BinReg(y=y,X=X,model="robit",df=df);
show(M);


## Inference

The same hypotheses considered previously are tested for the robit model. Note that the degrees of freedom requires specification.

cat("Test of b1=b2=b3=b4=0:\n");
Score.BinReg(y=y,X=X,L=c(F,T,T,T,T),model="robit",df=df,report=F);
cat("\n");
cat("Test of b4=0:\n");
Score.BinReg(y=y,X=X,L=c(F,F,F,F,T),model="robit",df=df,report=F);
cat("\n");
cat("Test of b2=0, b4=2:\n");
Score.BinReg(y=y,X=X,L=c(F,F,T,F,T),b10=c(0,2),model="robit",df=df,report=F);
cat("\n");
cat("Test of b1=b3=-1:\n");
Score.BinReg(y=y,X=X,L=c(F,T,F,T,F),b10=c(-1,-1),model="robit",df=df,report=F);
cat("\n");


zrmacc/BinReg documentation built on May 9, 2019, 8:08 a.m.