ltsgreg <-
function(x, y, tr = 0.2, h = NA)
{
#
# Compute the least trimmed absolute value regression estimator.
# The default amount of trimming is .2
x<-as.matrix(x)
library(MASS)
X<-cbind(x,y)
X<-elimna(X)
np<-ncol(X)
p<-np-1
x<-X[,1:p]
x<-as.matrix(x)
y<-X[,np]
if(is.na(h)) h <- length(y) - floor(tr * length(y))
temp<-ltsReg(y~x)$coef
START<-temp
coef<-nelderv2(X,np,FN=lts.sub,START=START,h=h)
res <- y - x%*%coef[2:np] - coef[1]
list(coef = coef, residuals = res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.