Try this using builtin data set BOD:
medsq <- function(p, DF) median((p[1] + p[2] * DF[[1]] - DF[[2]])^2) init <- coef(lm(demand ~ Time, BOD)) optim(init, medsq, DF = BOD) library(MASS) lqs(demand ~ Time, BOD, method = "lms") On 10/22/06, Pedro Mardones <[EMAIL PROTECTED]> wrote: > Does anyone can provide a code to implement least median squares > regression in R (not using the lqs function or calling C functions)? > Reason: teaching/learning purposes > Thanks > PM > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.