[R] linear model by month

Bill.Venables at csiro.au Bill.Venables at csiro.au
Tue May 29 03:21:28 CEST 2007


> dat <- 
+ "Month  ExcessReturn  Return  STO
+ 8  0.047595875  0.05274292  0.854352503
+ 8  0.016134874  0.049226941  4.399372005
+ 8  -0.000443869  0.004357305  -1.04980297
+ 9  0.002206554  -0.089068828  0.544809429
+ 9  0.021296551  0.003795071  0.226875834
+ 9  0.006741578  0.014104606  0.721986383
+ "
> dat <- read.table(textConnection(dat), header = T)
> dat <- transform(dat, Month = factor(paste("M", Month, sep="")))
> 
> FM <- lm(ExcessReturn ~ Month/(Return+STO) - 1, dat)
> 
> coef(FM)
       MonthM8        MonthM9 
  -0.014043930    0.028057112 
MonthM8:Return MonthM9:Return 
   1.291688338    0.097940939 
   MonthM8:STO    MonthM9:STO 
  -0.007593598   -0.031436815 
> 

#####
the coefficients are two intercepts, two slopes on Return, two slopes on
STO.

Why must it be "lm"?  It might be simple to use lmList from the nlme
package.

 


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile:                (I don't have one!)
Home Phone:                     +61 7 3286 7700
mailto:Bill.Venables at csiro.au
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Benoit Chemineau
Sent: Monday, 28 May 2007 11:48 PM
To: r-help at stat.math.ethz.ch
Subject: [R] linear model by month

Hi R-programmers !

I would like to perform a linear model regressio using the 'lm' function
and
i don't know how to do it.

The data is organised as below:
Month  ExcessReturn  Return  STO
8  0.047595875  0.05274292  0.854352503
8  0.016134874  0.049226941  4.399372005
8  -0.000443869  0.004357305  -1.04980297
9  0.002206554  -0.089068828  0.544809429
9  0.021296551  0.003795071  0.226875834
9  0.006741578  0.014104606  0.721986383

the model is:
ExcessReturn= a + b1*Return + b2*STO + u, u is the error term, a is the
intercept.

I would like to have monthly estimates of b1 and b2 using the least
squares
estimation. (b1month8 and b2month8, b1month9 and b2month9).

Thank you for your help !

	[[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.



More information about the R-help mailing list