find the intersection of abline with fitted curve

折月煮酒 提交于 2019-12-13 04:39:57

问题


I plotted a logistic curve with its fit using the following codes:

data:L50

str(L50)

'data.frame': 10 obs. of 3 variables:

$ Length.Class: int 50 60 70 80 90 100 110 120 130 140

$ Total.Ind : int 9 20 18 8 4 4 1 0 1 2

$ Mature.Ind : int 0 0 6 5 3 2 1 0 1 2

plot(L50$Mature.Ind/L50$Total.Ind ~ L50$Length.Class, data=L50,pch=20,xlab="Length class(cm)",ylab="Proportion of mature individuals")

glm.out<-glm(cbind(L50$Mature.Ind, L50$Total.Ind-L50$Mature.Ind) ~ L50$Length.Class,family=binomial(logit), data=L50)

glm.out Call: glm(formula = cbind(L50$Mature.Ind, L50$Total.Ind - L50$Mature.Ind) ~ L50$Length.Class, family = binomial(logit), data = L50)

Coefficients: (Intercept) L50$Length.Class
-8.6200 0.1053

Degrees of Freedom: 8 Total (i.e. Null); 7 Residual Null Deviance: 38.14 Residual Deviance: 9.924 AIC: 23.4

lines(L50$Length.Class, glm.out$fitted,type="l", col="red",lwd=2)

abline(h=0.5,col="black",lty=2,lwd=2)

I got the following curve:

The question is that i need to find the point that corresponds to Y=0.5 on the fitted curve and draw a line segment through it with its value on the x-axis....Any help with that? Thank you

This is what you asked

dput(L50)

structure(list(Length.Class = c(50L, 60L, 70L, 80L, 90L, 100L, 110L, 120L, 130L, 140L), Total.Ind = c(9L, 20L, 18L, 8L, 4L, 4L, 1L, 0L, 1L, 2L), Mature.Ind = c(0L, 0L, 6L, 5L, 3L, 2L, 1L, 0L, 1L, 2L), MatF = c(0L, 0L, 1L, 4L, 1L, 2L, 0L, 0L, 1L, 2L), MatM = c(0L, 0L, 5L, 1L, 2L, 0L, 1L, 0L, 0L, 0L)), .Names = c("Length.Class", "Total.Ind", "Mature.Ind", "MatF", "MatM"), class = "data.frame", row.names = c(NA,-10L))


回答1:


Your coefficients say that y = -8.62 + 0.1053x, so x = (glm.out$family$linkfun(.5)+8.62)/ 0.1053. Having said that, you'll probably want to use a well documented function, such as dose.p(myFit, 0.5) from the MASS package, so that you also get standard errors etc.



来源:https://stackoverflow.com/questions/22908912/find-the-intersection-of-abline-with-fitted-curve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!