Learn R Programming

statuser (version 0.1.9)

reg2: Two-Line Interrupted Regression

Description

Performs an interrupted regression analysis with heteroskedastic robust standard errors. This function fits two regression lines with a breakpoint at a specified value of the first predictor variable.

Usage

reg2(f, xc, graph = 1, family = "gaussian", data = NULL)

Value

A list containing:

  • b1, b2: Slopes of the two regression lines

  • p1, p2: P-values for the slopes

  • z1, z2: Z-statistics for the slopes

  • u.sig: Indicator (0/1) for whether u-shape is significant

  • xc: The breakpoint value

  • glm1, glm2: The fitted GLM models

  • rob1, rob2: Robust coefficient test results

  • msg: Messages about standard error computation

  • yhat.smooth: Fitted smooth values (if graph=1)

Arguments

f

A formula object specifying the model (e.g., y ~ x1 + x2 + x3). The first predictor is the one on which the u-shape is tested.

xc

Numeric value specifying where to set the breakpoint.

graph

Integer. If 1 (default), produces a plot. If 0, no plot is generated.

family

Character string specifying the family for the GLM model. Default is "gaussian" for OLS regression. Use "binomial" for probit models.

data

A data frame containing the variables in the formula.

Details

This function fits two interrupted regression lines with heteroskedastic robust standard errors using the sandwich package. The first predictor variable is split at the breakpoint xc, creating separate slopes before and after the breakpoint.