Skip to content

help on regression by subsets in dataset

3 messages · Krishna Kumar, Dimitris Rizopoulos, Gabor Grothendieck

#
Hi Everyone

May I request for a small help while performing the regression analysis.

I would like to know is there any possibility of conducting the
regression for different data subsets (in the same data file),
classified on the basis of "grouping variable". The alternative for
this is running the regression for n number of times which you all
know is quite cumbersome.

Thank you for your kind attention and help

rgds

krishna
#
you could use function lmList() from the nlme package, i.e.,

dat <- data.frame(y = rnorm(120), x = runif(120, -3, 3), g = rep(1:3, 
each = 40))
############
library(nlme)
m <- lmList(y ~ x | g, data = dat)
m
summary(m)

I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Krishna" <snvk4u at gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, August 08, 2005 12:20 PM
Subject: [R] help on regression by subsets in dataset
#
On 8/8/05, Krishna <snvk4u at gmail.com> wrote:
This defines a model which has a separate intercept and slope for
each value of the grouping variable g:
[1] 1 1 1 2 2 2 3 3 3 4 4 4
Levels: 1 2 3 4
Call:
lm(formula = y ~ g/x - 1)

Coefficients:
      g1        g2        g3        g4      g1:x      g2:x      g3:x      g4:x  
-0.21697   6.40748   0.24710  -3.29170  -0.10459  -1.20787   0.04418   0.34762