[R] Help using mapply to run multiple models

Simon Kiss sjkiss at gmail.com
Wed Dec 18 02:53:58 CET 2013


I think I'm missing something.  I have a data frame that looks below.  
sample.df<-data.frame(var1=rbinom(50, size=1, prob=0.5), var2=rbinom(50, size=2, prob=0.5), var3=rbinom(50, size=3, prob=0.5), var4=rbinom(50, size=2, prob=0.5), var5=rbinom(50, size=2, prob=0.5))

I'd like to run a series of univariate general linear models where var1 is always the dependent variable and each of the other variables is the independent. Then I'd like to summarize each in a table.
I've tried : 

sample.formula=list(var1~var2, var1 ~var3, var1 ~var4, var1~var5)
mapply(glm, formula=sample.formula, data=list(sample.df), family='binomial')

And that works pretty well, except, I'm left with a matrix that contains all the information I need. I can't figure out how to use summary() properly on this information to usefully report that information. 

Thank you for any suggestions. 

*********************************
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9



More information about the R-help mailing list