GLM Coding Issue
On Nov 27, 2012, at 3:34 PM, Steve Lianoglou wrote:
Hi, Comments inline: On Tue, Nov 27, 2012 at 1:00 PM, Craig P O'Connell <coconnell2 at umassd.edu> wrote:
Dear all,
I am having a recurring problem when I attempt to conduct a GLM.
Here is what I am attempting (with fake data):
First, I created a txt file, changed the directory in R (to the
proper folder containing the file) and loaded the file:
#avoid<-read.table("avoid.txt",header=TRUE);avoid
# treatment feeding avoid noavoid
#1 control nofeed 1 357
#2 control feed 2 292
#3 control sat 4 186
#4 proc nofeed 15 291
#5 proc feed 25 288
#6 proc sat 17 140
#7 mag nofeed 87 224
#8 mag feed 34 229
#9 mag sat 46 151
I then try to "attach(avoid)" the data, but continue to get an
error message ( The following object(s) are masked
_by_ .GlobalEnv :), so to fix this, I do the following:
That was not an error message but rather a warning message. (You are asked to copy the full text.)
#newavoid<-avoid #newavoid (does this do anything?)
It essentially makes a copy of `avoid` to `newavoid` -- what did you want it to do? That having been said, a good rule of thumb is to never use `attach`, so let's avoid it for now.
Lastly, I have several GLM's I wanted to conduct. Please see the following: #model1<-glm(cbind(avoid, noavoid)~treatment,data=,family=binomial) #model2=glm(cbind(avoid, noavoid)~feeding, familiy=binomial) #model3=glm(cbind(avoid, noavoid)~treatment+feeding, familiy=binomial)
`cbind`-ing doesn't make much sense here. What is your target (y) variable here? are you trying to predict `avoid` or `noavoid` status?
Sorry, Steve. It does make sense. See : ?glm # First paragraph of Details.
Let's assume you were "predicting" `noavoid` from just `treatment` and `feeding` (I guess you have more data (rows) than you show), you would build a model like so: R> model <- glm(noavoid ~ treatment + feeding, binomial, avoid) Or to be explicit about the parameters: R> model <- glm(noavoid ~ treatment + feeding, family=binomial, data=avoid)
It would be greatly appreciated if somebody can help me with my coding, as you can see I am a novice but doing my best to learn. I figured if I can get model1 to run, I should be able to figure out the rest of my models.
Since you're just getting started, maybe it would be helpful for people writing documentation/tutorials/whatever what needs to be explained better. For instance, I'm curious why you thought to `cbind` in your first glm call, which was: model1<-glm(cbind(avoid, noavoid)~treatment,data=,family=binomial) What did you think `cbind`-ing was accomplishing for you? Is there an example somewhere that's doing that as the first parameter to a `glm` call? Also, why just have `data=<nothing>`? I'm not criticizing, just trying to better understand. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
______________________________________________ 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.
David Winsemius, MD Alameda, CA, USA