Skip to content

Same regression per sub-group: apply?

4 messages · Rense Nieuwenhuis, Dimitris Rizopoulos, Romain Francois +1 more

#
try something like this (untested):

dataCountry <- split(data, data$COUNTRY)
model.per.country <- lapply(dataCountry, function (x) {
    glm(dependent.var ~ FEMALE + AGE + EDUCLIN, family = binomial, 
data = x)
})


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/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Rense Nieuwenhuis" <r.nieuwenhuis at student.ru.nl>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, December 07, 2007 9:32 AM
Subject: [R] Same regression per sub-group: apply?
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
#
What about ?by, something like this (still untested):

model.per.country <- by( data, data$COUNTRY, function (x) {
    glm(dependent.var ~ FEMALE + AGE + EDUCLIN, family = binomial, data = x)
})

Or

model.per.country <- by( data, data$COUNTRY, 
  glm , dependent.var ~ FEMALE + AGE + EDUCLIN, family = binomial )


Cheers,

Romain
Dimitris Rizopoulos wrote:

  
    
#
See:

https://stat.ethz.ch/pipermail/r-help/2007-May/132866.html
On Dec 7, 2007 3:32 AM, Rense Nieuwenhuis <r.nieuwenhuis at student.ru.nl> wrote: