[R] glm automation

Liaw, Andy andy_liaw at merck.com
Wed Mar 8 03:29:07 CET 2006


From: ronggui
> 
> 2006/3/8, A Mani <a.manigs at gmail.com>:
> > Hello,
> >         I have two problems in automating multiple glm(s) 
> operations. 
> > The data file is tab delimited file with headers and two 
> columns. like
> >
> > "ABC"  "EFG"
> > 1  2
> > 2  3
> > 3  4
> > dat <- read.table("FILENAME", header=TRUE, sep="\t", 
> na.strings="NA", 
> > dec=".", strip.white=TRUE) dataf <- read.table("FILENAME", 
> > header=FALSE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE)
> > norm1 <- glm(dataf[1,1] ~ dataf[1,2], family= normal(log), data=dat)
> > norm2 <- glm(dataf[1,1] ~ dataf[1,2], family= 
> normal(identity), data=dat)
> > and so on.
> It should be
>  norm1 <- glm(dataf[,1] ~ dataf[,2], family= normal(log), 
> data=dat)  norm2 <- glm(dataf[,1] ~ dataf[,2], family= 
> normal(identity), data=dat)
> 
> you should read the document of "[" about how to use index.

I wish people would just give up on (ab)using model formula like that.  IMHO
it's really asking for trouble down the road.  For example:

> n <- 5
> d1 <- data.frame(x=1:n, y=rnorm(n))
> d2 <- data.frame(u=n:1, v=rnorm(n))
> d3 <- data.frame(y=rnorm(n), x=n:1)
> f1 <- lm(d1[,2] ~ d1[,1], data=d1)
> f2 <- lm(y ~ x, data=d1)
> predict(f1)
           1            2            3            4            5 
-1.767697694 -1.326691900 -0.885686106 -0.444680312 -0.003674518 
> predict(f2)
           1            2            3            4            5 
-1.767697694 -1.326691900 -0.885686106 -0.444680312 -0.003674518 
> predict(f1, d2)
           1            2            3            4            5 
-1.767697694 -1.326691900 -0.885686106 -0.444680312 -0.003674518 

Notice anything odd above?  

> predict(f2, d3)
           1            2            3            4            5 
-0.003674518 -0.444680312 -0.885686106 -1.326691900 -1.767697694 

Now that's more like it...

Andy


 
> > But glm does not work on the data unless I write ABC and 
> EFG there... 
> > I want to automate the script for multiple files.
> >
> > The other problem is to write the plot(GLM) to a file without  
> > displaying it at stdout.
> >
> > Thanks,
> >
> >
> > A. Mani
> > Member, Cal. Math. Soc
> >
> >         [[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
> >
> 
> 
> --
> »ÆÈÙ¹ó
> Deparment of Sociology
> Fudan University
> 
>




More information about the R-help mailing list