vincent chouraki
2008-Feb-25 15:05 UTC
[R] "by" function "half-working" when used in a custom function
Dear R users, I'm trying to save the results of separate logistic regression analyses of a dataset according to a categorical factor. For that, I first used a "by" function such as following : temp <- by( data, data$categorical.factor , function(x) summary( glm( formula = data$var1 ~ data$var2 , data = x , family = binomial("logit")))) and it worked perfectly well Next I tried to create a custom function that contains the latter syntax regtab <- function(category, arg1, arg2 , data){ temp <-by( data, category , function(x) summary( glm( formula= arg1 ~ arg2 , data=x , family = binomial("logit")))) temp } the resulting object of this function is a list with the correct subgroup categories as its element's names but with the results of the entire dataset logistic regression as its elements. I can't figure out what's going on. Do you have any clues ? Many thanks in advance, Vincent Chouraki, Interne de Santé Publique, CHRU-Lille, France. _____________________________________________________________________________ [[alternative HTML version deleted]]
Gabor Grothendieck
2008-Feb-25 15:55 UTC
[R] "by" function "half-working" when used in a custom function
Please give minimal reproducible examples. The data and a test driver were missing. See last line to every message to r-help. The problem is discussed here: http://tolstoy.newcastle.edu.au/R/help/06/08/32017.html On Mon, Feb 25, 2008 at 10:05 AM, vincent chouraki <vchouraki at yahoo.fr> wrote:> Dear R users, > > I'm trying to save the results of separate logistic regression analyses of a dataset according to a categorical factor. For that, I first used a "by" function such as following : > > temp <- by( data, data$categorical.factor , function(x) summary( glm( formula = data$var1 ~ data$var2 , data = x , family = binomial("logit")))) > > and it worked perfectly well > > Next I tried to create a custom function that contains the latter syntax > > regtab <- function(category, arg1, arg2 , data){ > > temp <-by( data, category , function(x) summary( glm( formula= arg1 ~ arg2 , data=x , family = binomial("logit")))) > > temp > > } > > the resulting object of this function is a list with the correct subgroup categories as its element's names but with the results of the entire dataset logistic regression as its elements. > > I can't figure out what's going on. Do you have any clues ? > > Many thanks in advance, > > Vincent Chouraki, > Interne de Sant? Publique, > CHRU-Lille, France. > > > > > > _____________________________________________________________________________ > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org 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. > >
Seemingly Similar Threads
- [Hmisc] latex() with ctable=T inserting unwanted empty line in .tex file when used on summary.formula(method="reverse") object
- [R 2.12] install.packages() with no lib argument does not work
- Prediction interval of Y using BMA
- methods package not loaded by default when using Rscript in R2.13
- Create pdf and postscript files