Dear R Wizards,

After much frustration and days of confusion I have finally broken down and
am asking for help, which I don’t like doing, but I just can’t figure this
one out on my own.  I’ve conducted a laboratory experiment testing the
effects of temperature and salinity on whether or not a biological event
will occur (Go or NoGo).  I’ve coded the factors temperature and salinity
as factors for the binomial glm, and I haven’t had any trouble fitting the
model and checking assumptions.

I am however having trouble with the predict.glm function.  I want to
create a graph using my data that is similar to the one produced by the
budworm example at the bottom of the predict.glm R documentation.  In my
case I want temperature on the x axis, probability on the y axis, and the
lines on the graph to represent the probability of the event occurring at
the different salinities tested at the different temperatures.

I created a smaller version of my data and have included it and the R code
I used below.  I get two main problems that I hope you’re willing to help
with.

1.  When I input the text argument the output in the graph gives salinity
values that are superimposed on one another.  And, the values don’t seem to
make sense – they are returned as probabilities of either 1.0 or 0.

2.  When I input the lines argument I get the following error messages:

Error: variable 'fTemp' was fitted with type "factor" but type "numeric"
was supplied

In addition: Warning message:

In model.frame.default(Terms, newdata, na.action = na.action, xlev =
object$xlevels) :  variable 'fTemp' is not a factor

grrrrrrrrrr

Pleasehelp<-read.table("Rhelp.txt",h=T)

attach(Pleasehelp)

fix(Pleasehelp)

Temp  Sal   Go    Total

5     34    1     1

5     34    1     1

5     34    1     1

5     21    1     1

5     21    1     1

5     21    0     1

10    34    1     1

10    34    0     1

10    34    1     1

10    21    1     1

10    21    0     1

10    21    0     1

15    34    0     1

15    34    0     1

15    34    0     1

15    21    0     1

15    21    0     1

15    21    0     1

fTemp<-factor(Temp)

fSal<-factor(Sal)

Go<-Go

NoGo<-Total-Go

Went<-cbind(Go,NoGo)

DF<-data.frame(fTemp,fSal,Went,Total)

glm<-glm(Went~fTemp+fSal+fTemp*fSal,family="binomial",data=DF)

require(graphics)

plot(c(5,15),c(0,1),type="n",xlab="Temperature",ylab="Probability of going")

text(Temp,Go/Total,as.character(Sal))

ld<-(seq(5,15,1))

lines(ld,predict(glm,data.frame(fTemp=ld,fSal=factor(rep("34",length(ld)),levels=levels(fSal))),type="response"))



Thank you very much for your time and expertise!

Kindly,

Chad

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to