linrclus {cluscov}R Documentation

Linear regression via coordinate descent with covariate clustering

Description

Covariate assignment to k clusters using the coordinate descent algorithm. This function is a wrapper for the C function linreg_coord_clus

Usage

linrclus(Y, X, k, coefs, clus, clusmns, nC = 1, x = FALSE)

Arguments

Y

vector of outcome variable

X

matrix of covariates. Should not include 1's for the intercept

k

number of clusters

coefs

vector of coefficients as starting values. Should not include the intercept.

clus

vector of covariate cluster assignments as starting values

clusmns

vector k cluster parameter centers

nC

first nC-1 covariates in X not to cluster. Must be at least 1 for the intercept

x

a logical for returning the design matrix

Value

clus cluster assignments

coefs vector of coefficients as starting values

clusmns vector of cluster means

Examples

set.seed(14) #Generate data
N = 1000; (bets = rep(-2:2,4)); p = length(bets); X = matrix(rnorm(N*p),N,p)
Y = cbind(1,X)%*%matrix(c(0.5,bets),ncol = 1)
begin_v<- rep(NA,p)
for (j in 1:p) {
 begin_v[j] = stats::coef(lm(Y~X[,j]))[2]
}
set.seed(12); klus_obj<- kmeans(begin_v,centers = 5)
linrclus(Y,X,k=5,coefs=c(0,begin_v),clus=klus_obj$cluster,clusmns=klus_obj$centers)

[Package cluscov version 1.1.0 Index]