R/rvsel_forward.R

rvsel_forward <- function(x,y,method,lambda){

p = ncol(x)

out3 = rep(0,p)
pre.max = NULL

	for(step.i in 1:p){

	if(step.i!=1){pre.max <- post.max}

	choosed = which(out3!=0)

	if(step.i==1){CB=diag(1,p)
	} else {CB=diag(step.i,p);CB[,choosed]=rep(out3[choosed],each=p);CB=CB[-choosed,]}

	if(is.vector(CB)){CB=t(as.matrix(CB))}

	step.score=rep(NA,nrow(CB))

		for(k in 1:nrow(CB)){
		stepCM = as.matrix(x[,which(CB[k,]!=0)])
			if(method=="cmc")	{step.score[k]=rvsel_cmc(stepCM,y)
			} else {step.score[k]=rvsel_sum(stepCM,y)}
		}
	post.max = max(step.score)

	if(step.i!=1){if(post.max - pre.max < lambda ) break}

	out3 = CB[which.max(step.score),]
	out2 = post.max
	out1 = as.numeric(out3!=0)
	}
out3 = which(out3!=0)[order(out3[which(out3!=0)])]

return(list(selection=out1,score=out2,sequence=out3))
}

Try the rvsel package in your browser

Any scripts or data that you put into this service are public.

rvsel documentation built on April 14, 2017, 7:15 p.m.