1
$\begingroup$

I'm a newbie to R and am hoping someone can show me the error of my ways. I'm getting what appears to be a logistic regression and plot but I wasn't expecting the slope around 25.2 to be so steep and was expecting a more typical logistic curve.

Also, the glm function threw a couple warnings but I don't think it's necessarily indicative of a problem.

Warning messages:
1: glm.fit: algorithm did not converge 
2: glm.fit: fitted probabilities numerically 0 or 1 occurred 

p1ShapeResponse <- structure(list(Response = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), Temperature = c(23.74959742, 23.77777778,23.88043478,24.00322061,24.0394525,24.06360709,24.19041868,24.25885668,24.30112721,24.50040258,24.5326087,24.76811594,24.78019324,24.82045089,24.87077295,24.94927536,25.0821256,25.41022544,25.65982287,25.82085346)), .Names = c("Response", "Temperature"), class = "data.frame", row.names = c(NA, -27L))
p1Shape.glm <- glm(Response ~ Temperature, data=p1ShapeResponse, family=binomial(link=logit))

plot(p1ShapeResponse$Temperature, p1ShapeResponse$Response, xlab="Mean Temperature", ylab="")
curve(predict(p1Shape.glm, data.frame(Temperature=x), type="resp"), add=TRUE, col="black")
mtext("p1 Shape", side=2, line=2, col="blue")
axis(side=1,col="black",col.axis="black",las=1)
points(p1ShapeResponse$Temperature,fitted(p1Shape.glm),pch=20)


p2ShapeResponse <- structure(list(Response = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L), Temperature = c(23.74577573, 23.77265745, 23.88018433, 23.99923195, 24.00691244, 24.03763441, 24.05683564, 24.19124424, 24.26036866, 24.30261137, 24.4984639, 24.53302611, 24.76728111, 24.7749616, 24.8172043, 24.87096774, 25.4124424, 25.65821813, 25.82334869)), .Names = c("Response", "Temperature"), class = "data.frame", row.names = c(NA, -27L))
p2Shape.glm <- glm(Response ~ Temperature, data=p2ShapeResponse, family=binomial(link=logit))

## Allow a second plot on the same graph
par(new = TRUE)

## Plot the second plot and put axis scale on right
plot(p2ShapeResponse$Temperature, p2ShapeResponse$Response, axes=FALSE, bty="n", pch="+", col="blue", xlab="", ylab="")
curve(predict(p2Shape.glm, data.frame(Temperature=x), type="resp"), add=TRUE, col="blue")

## a little farther out (line=4) to make room for labels
mtext("p2 Shape", side=4, line=2, col="blue")
axis(side=4, col="blue",col.axis="blue",las=1)
$\endgroup$
2

0

Browse other questions tagged or ask your own question.