Hi R-help,
How do you perform least median square regression in R? Here is what I have but
received no output.
LMSRegression <- function(df, indices){
sample <- df[indices, ]
LMS_NAR_NIC_relation <- lm(sample$NAR~sample$NIC, data = sample, method =
"lms")
rsquared_lms_nar_nic <- summary(LMS_NAR_NIC_relation)$r.square
LMS_SQRTNAR_SQRTNIC_relation <- lm(sample$SQRTNAR~sample$SQRTNIC, data =
sample, method = "lms")
rsquared_lms_sqrtnar_sqrtnic <-
summary(LMS_SQRTNAR_SQRTNIC_relation)$r.square
out <- c(rsquared_lms_nar_nic, rsquared_lms_sqrtnar_sqrtnic)
return(out)
}
Also, which value should be looked at decide whether this is best regression
model to use?
Bryan Mac
bryanmac.24 at gmail.com
[[alternative HTML version deleted]]
Hello,
Use package quantreg, function rq().
install.packages("quantreg")
?rq
Hope this helps,
Rui Barradas
Citando Bryan Mac <bryanmac.24 at gmail.com>:
> Hi R-help,
>
> How do you perform least median square regression in R? Here is what
> I have but received no output.
>
> LMSRegression <- function(df, indices){
> sample <- df[indices, ]
> LMS_NAR_NIC_relation <- lm(sample$NAR~sample$NIC, data = sample,
> method = "lms")
> rsquared_lms_nar_nic <- summary(LMS_NAR_NIC_relation)$r.square
>
> LMS_SQRTNAR_SQRTNIC_relation <- lm(sample$SQRTNAR~sample$SQRTNIC,
> data = sample, method = "lms")
> rsquared_lms_sqrtnar_sqrtnic <-
> summary(LMS_SQRTNAR_SQRTNIC_relation)$r.square
>
> out <- c(rsquared_lms_nar_nic, rsquared_lms_sqrtnar_sqrtnic)
> return(out)
> }
>
> Also, which value should be looked at decide whether this is best
> regression model to use?
>
> Bryan Mac
> bryanmac.24 at gmail.com
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
On Sat, 08 Oct 2016, Bryan Mac <bryanmac.24 at gmail.com> writes:> Hi R-help, > > How do you perform least median square regression in R? Here is what I have but received no output. > > LMSRegression <- function(df, indices){ > sample <- df[indices, ] > LMS_NAR_NIC_relation <- lm(sample$NAR~sample$NIC, data = sample, method = "lms") > rsquared_lms_nar_nic <- summary(LMS_NAR_NIC_relation)$r.square > > LMS_SQRTNAR_SQRTNIC_relation <- lm(sample$SQRTNAR~sample$SQRTNIC, data = sample, method = "lms") > rsquared_lms_sqrtnar_sqrtnic <- summary(LMS_SQRTNAR_SQRTNIC_relation)$r.square > > out <- c(rsquared_lms_nar_nic, rsquared_lms_sqrtnar_sqrtnic) > return(out) > } > > Also, which value should be looked at decide whether this is best regression model to use? > > Bryan Mac > bryanmac.24 at gmail.com >A tutorial on how to run such regressions is included in the NMOF package. https://cran.r-project.org/package=NMOF/vignettes/PSlms.pdf -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net
I am confused reading the document. I have installed and added the package (MASS). What is the function for LMS Regression? Bryan Mac bryanmac.24 at gmail.com> On Oct 8, 2016, at 6:17 AM, Enrico Schumann <es at enricoschumann.net> wrote: > > On Sat, 08 Oct 2016, Bryan Mac <bryanmac.24 at gmail.com> writes: > >> Hi R-help, >> >> How do you perform least median square regression in R? Here is what I have but received no output. >> >> LMSRegression <- function(df, indices){ >> sample <- df[indices, ] >> LMS_NAR_NIC_relation <- lm(sample$NAR~sample$NIC, data = sample, method = "lms") >> rsquared_lms_nar_nic <- summary(LMS_NAR_NIC_relation)$r.square >> >> LMS_SQRTNAR_SQRTNIC_relation <- lm(sample$SQRTNAR~sample$SQRTNIC, data = sample, method = "lms") >> rsquared_lms_sqrtnar_sqrtnic <- summary(LMS_SQRTNAR_SQRTNIC_relation)$r.square >> >> out <- c(rsquared_lms_nar_nic, rsquared_lms_sqrtnar_sqrtnic) >> return(out) >> } >> >> Also, which value should be looked at decide whether this is best regression model to use? >> >> Bryan Mac >> bryanmac.24 at gmail.com >> > > A tutorial on how to run such regressions is included > in the NMOF package. > > https://cran.r-project.org/package=NMOF/vignettes/PSlms.pdf > > > -- > Enrico Schumann > Lucerne, Switzerland > http://enricoschumann.net