Hi does anyone know how to do a logistic regression in R? any help appreciated Carl -- View this message in context: http://r.789695.n4.nabble.com/Logistic-regression-tp4512658p4512658.html Sent from the R help mailing list archive at Nabble.com.
On Wed, Mar 28, 2012 at 11:49 AM, carlb1 <carl19_87 at hotmail.com> wrote:> Hi > > does anyone know how to do a logistic regression in R?I do. And doubtless many other folks on R-help do too.> any help appreciatedYou should probably start here: http://www.rseek.org/?cx=010923144343702598753%3Aboaz1reyxd4&q=logistic+regression&sa=Search+functions%2C+lists%2C+and+more&cof=FORID%3A11&siteurl=rseek.org%2F&ref And then move on to here:> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Sarah Goslee http://www.functionaldiversity.org
I am trying to plot the logistic regression of a dataset (# of living flies vs days the flies are alive) and then fit a best-fit line to this data. Here is my code: plot(fflies$living~fflies$day,xlab="Number of Days",ylab="Number of Fruit Flies",main="Number of Living Fruit Flies vs Day",pch=16) alive <- (fflies$living) dead <- (fflies$living[1]-alive) glm.fit <- glm(cbind(alive,dead)~fflies$day,family="binomial") summary(glm.fit) lines(sort(fflies$day),fitted(glm.fit) [order (fflies$day)],col "red",lwd=2) lines(glm.fit,col = "red",lwd=2) My problem is that, while I am pretty sure that I did the 'glm' command correctly, when I try to plot this as a best-fit line on my data, it does not fit (clearly on a different scale somehow). Can anyone enlighten me about what I am doing wrong? Should I be scaling one of these somehow? I've tried various types of scaling but nothing plots the line on top of the plot (no matter which I scale). Thanks so much for whatever help you can give me! Cheers, Melissa -- View this message in context: http://r.789695.n4.nabble.com/logistic-regression-tp4530651p4530651.html Sent from the R help mailing list archive at Nabble.com.
On Apr 3, 2012, at 9:25 PM, Melrose2012 wrote:> I am trying to plot the logistic regression of a dataset (# of > living flies > vs days the flies are alive) and then fit a best-fit line to this > data. > > Here is my code: > plot(fflies$living~fflies$day,xlab="Number of Days",ylab="Number of > Fruit > Flies",main="Number of Living Fruit Flies vs Day",pch=16) > alive <- (fflies$living) > dead <- (fflies$living[1]-alive) > glm.fit <- glm(cbind(alive,dead)~fflies$day,family="binomial") > summary(glm.fit) > lines(sort(fflies$day),fitted(glm.fit) [order (fflies$day)],col > "red",lwd=2) > lines(glm.fit,col = "red",lwd=2)Is this homework?> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html-- David Winsemius, MD West Hartford, CT