Least Median Square Regression

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Least Median Square Regression

bmac
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
[hidden email]




        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Least Median Square Regression

Rui Barradas
Hello,


Use package quantreg, function rq().

install.packages("quantreg")
?rq

Hope this helps,

Rui Barradas

Citando Bryan Mac <[hidden email]>:

> 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
> [hidden email]
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Least Median Square Regression

Enrico Schumann-2
In reply to this post by bmac
On Sat, 08 Oct 2016, Bryan Mac <[hidden email]> 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
> [hidden email]
>

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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Least Median Square Regression

bmac
I am confused reading the document.

I have installed and added the package (MASS).

What is the function for LMS Regression?


Bryan Mac
[hidden email]



> On Oct 8, 2016, at 6:17 AM, Enrico Schumann <[hidden email]> wrote:
>
> On Sat, 08 Oct 2016, Bryan Mac <[hidden email]> 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
>> [hidden email]
>>
>
> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Least Median Square Regression

Bert Gunter-2
Well, first of all, note that there is no "lms" method for the stats
package's lm() function. You can't just make stuff up, you know!

And second, ?lmsreg -- after loading MASS via library(MASS), if you
haven't already done this after your install --  is what you want.
Other than ?lmsreg and what Enrico pointed you to, however, you'll
have to manage on your own. Statistical tutorials are not the remit of
this list. You might wish to consult with someone locally for help.
You may be able to get an answer to a post of a specific question
about usage **if you post code that fails** and otherwise follow the
posting guide (below).

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Oct 8, 2016 at 1:10 PM, Bryan Mac <[hidden email]> wrote:

> I am confused reading the document.
>
> I have installed and added the package (MASS).
>
> What is the function for LMS Regression?
>
>
> Bryan Mac
> [hidden email]
>
>
>
>> On Oct 8, 2016, at 6:17 AM, Enrico Schumann <[hidden email]> wrote:
>>
>> On Sat, 08 Oct 2016, Bryan Mac <[hidden email]> 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
>>> [hidden email]
>>>
>>
>> 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
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Least Median Square Regression

Enrico Schumann-2
In reply to this post by bmac
On Sat, 08 Oct 2016, Bryan Mac <[hidden email]> writes:

> I am confused reading the document.
>
> I have installed and added the package (MASS).
>
> What is the function for LMS Regression?
>

In MASS, it is 'lqs'.

But the vignette provides a code example for how to
compute 'manually' an LMS-regression, i.e. how to do
the actual optimisation.

>
>> On Oct 8, 2016, at 6:17 AM, Enrico Schumann <[hidden email]> wrote:
>>
>> On Sat, 08 Oct 2016, Bryan Mac <[hidden email]> 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
>>> [hidden email]
>>>
>>
>> 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

______________________________________________
[hidden email] 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.