# varGuid: variance-guided regression for heteroscedastic linear models

### Authors
Sibei Liu (sxl4188@miami.edu) and Min Lu (luminwin@gmail.com)

### Reference
Liu, S. and Lu, M. (2026). *Variance-Guided Regression for Heteroscedastic Data*.
TechRxiv. DOI: 10.36227/techrxiv.177004877.75352102/v1

### Description
The CRAN release of **varGuid** implements the global linear mean-variance model
from Section 2 of the paper via iteratively reweighted least squares (IRLS) and
iteratively reweighted lasso estimation. For the grouping-based nonlinear
prediction extension from Section 3 of the paper, please use the development
version available at:

```r
devtools::install_github("luminwin/varGuid")
```

### Installation

```r
install.packages("varGuid")
library(varGuid)
```

### Examples

```r
data(cobra2d, package = "varGuid")
dat <- cobra2d
set.seed(1)
tid <- sample(seq_len(nrow(dat)), 200)
train <- dat[-tid, ]
test <- dat[tid, ]
yid <- which(colnames(dat) == "y")
```

#### IRLS / weighted least squares fit

```r
o <- lmv(X = train[, -yid], Y = train[, yid], lasso = FALSE)
summary(o$obj.varGuid)  # varGuid weighted fit
summary(o$obj.OLS)      # baseline OLS fit

head(prd(o, train[, -yid], model = "baseline"))
head(prd(o, train[, -yid], model = "varGuid"))

# The corresponding base R calls are:
head(stats::predict(o$obj.OLS, newdata = as.data.frame(train[, -yid])))
head(stats::predict(o$obj.varGuid, newdata = as.data.frame(train[, -yid])))
```

#### Iteratively reweighted lasso fit

```r
o2 <- lmv(X = train[, -yid], Y = train[, yid], lasso = TRUE)
o2$beta            # varGuid-lasso coefficients
o2$obj.lasso$beta  # baseline lasso coefficients

head(prd(o2, train[, -yid], model = "baseline"))
head(prd(o2, train[, -yid], model = "varGuid"))

# The corresponding glmnet calls are:
head(drop(glmnet::predict.glmnet(o2$obj.lasso,
                                 newx = as.matrix(train[, -yid]))))
head(drop(glmnet::predict.glmnet(o2$obj.varGuid,
                                 newx = as.matrix(train[, -yid]))))
```
