Description Usage Arguments Value Examples
Covariate assignment to k clusters using the coordinate descent algorithm. This
function is a wrapper for the C
function linreg_coord_clus
1 |
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 |
clus cluster assignments
coefs vector of coefficients as starting values
clusmns vector of cluster means
1 2 3 4 5 6 7 8 9 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.