[R] Multivariate regression

Ravi Varadhan rvaradhan at jhmi.edu
Tue Oct 31 20:59:57 CET 2006


Thank you Robin (also thanks to Andris and Bernhard). I did get answers to
my problem using "lm" as you had suggested. But my main concern is about
getting the appropriate standard errors for \hat{beta}.  

My response is actually preference data, where each individual ranks a list
of k items, assigning them unique ranks from 1 to k.  Since the ranks for
each item are negatively-correlated within an individual, I would like to
take this into consideration.  Although "lm" gives me correct parameter
estimates, I think that the standard errors are overestimated.

Best,
Ravi.

----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 

----------------------------------------------------------------------------
--------

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Robin Hankin
Sent: Monday, October 30, 2006 4:17 AM
To: Andris Jankevics
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Multivariate regression

Hi

I discovered the other day that lm() does some of the work for
you:

library(mvtnorm)

X <- matrix(rnorm(60),ncol=3)
beta  <- matrix(1:6,ncol=2)
sig <- matrix(c(1,0.7,0.7,1),2,2)

Y <- X %*% beta + rmvnorm(n=20,sigma=sig)


  lm(Y ~ X-1)

Call:
lm(formula = Y ~ X - 1)

Coefficients:
     [,1]   [,2]
X1  1.015  4.065
X2  2.483  5.366
X3  2.762  5.727


This gives an estimate for beta.

But I don't know of a ready-made R solution for estimating
the covariance of  the elements of beta, or the "sig" matrix
for the covariance matrix of the observation errors.

Anyone?





On 30 Oct 2006, at 09:01, Andris Jankevics wrote:

> Also you can take a look on Partial Least Squares (PLS) regression.
> http://www.statsoft.com/textbook/stpls.html
> R-package: http://mevik.net/work/software/pls.html
>
> Andris Jankevics
>
> On Sestdiena, 28. Oktobris 2006 06:04, Ritwik Sinha wrote:
>> You can use gee (
>> http://finzi.psych.upenn.edu/R/library/geepack/html/00Index.html)  
>> or maybe
>> the function gls in nlme.
>>
>> Ritwik.
>>
>> On 10/27/06, Ravi Varadhan <rvaradhan at jhmi.edu> wrote:
>>> Hi,
>>>
>>>
>>>
>>> Suppose I have a multivariate response Y (n x k) obtained at a  
>>> set of
>>> predictors X (n x p).  I would like to perform a linear  
>>> regression taking
>>> into consideration the covariance structure of Y within each unit  
>>> - this
>>> would be represented by a specified matrix V (k x k), assumed to  
>>> be the
>>> same
>>> across units.  How do I use "lm" to do this?
>>>
>>>
>>>
>>> One approach that I was thinking of is as follows:
>>>
>>>
>>>
>>> Flatten Y to a vector, say, Yvec (n*k x 1).  Create Xvec (n*k,  
>>> p*k) such
>>> that it is made up of block matrices Bij (k x k), where Bij is a  
>>> diagonal
>>> matrix with X_ij as the diagonal (i = 1,.n, and j = 1,.,p).  Now  
>>> I can
>>> use "lm" in a univariate mode to regress Yvec against Xvec, with
>>> covariance matrix Vvec (n*k x n*k).  Vvec is a block-diagonal  
>>> matrix with
>>> blocks of V along the diagonal.  This seems like a valid  
>>> approach, but I
>>> still don't know how to specify the covariance structure to do  
>>> weighted
>>> least squares.
>>>
>>>
>>>
>>> Any help is appreciated.
>>>
>>>
>>>
>>> Best,
>>>
>>> Ravi.
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------------------- 
>>> -----
>>> --- -------
>>>
>>> Ravi Varadhan, Ph.D.
>>>
>>> Assistant Professor, The Center on Aging and Health
>>>
>>> Division of Geriatric Medicine and Gerontology
>>>
>>> Johns Hopkins University
>>>
>>> Ph: (410) 502-2619
>>>
>>> Fax: (410) 614-9625
>>>
>>> Email: rvaradhan at jhmi.edu
>>>
>>> Webpage:
>>> http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------------------- 
>>> -----
>>> --- --------
>>>
>>>
>>>
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at 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 at 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.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

______________________________________________
R-help at 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.



More information about the R-help mailing list