1

如何在绘图上叠加逻辑曲线。

Temp<-c(27.2,28.3,29.9) 
Temp 
male<-c(0,8,8) 
male 
female<-c(10,4,2)
female
table=read.table("E:\\Book1.txt",header=T)
attach(table) 
table 
Y=cbind(male,female) 
Y 
mylogit <- glm(Y ~ Temp, family = "binomial",table)
summary(mylogit) 

我需要为男性和女性叠加一条逻辑曲线

curve(predict(mylogit,data.frame(male=x),type="resp"),add=TRUE) 
title(main="Males Temperature with Fitted GLM Logistic Regression Line") 

任何帮助?

4

1 回答 1

1

你的代码有点混乱,所以这可能不是你想要的。

逻辑回归对事件发生的概率进行建模。因此,在您的情况下,您正在males根据数据对概率进行建模,给出males三个不同的比例Temp,例如 0/10、8/12 (.66) 和 8/10 (0.8)。因此,要将模型与数据进行比较,您必须绘制预测响应与男性分数的关系。

Temp    <- c(27.2,28.3,29.9) 
male    <- c(0,8,8) 
female  <- c(10,4,2)
Y       <- cbind(male,female)  
mylogit <- glm(Y ~ Temp, family = "binomial")
plot(Temp,predict(mylogit,type="resp"),
     type="b",col="blue",lty=2, 
     ylim=c(0,1),ylab="Fraction of Males",
     main="Males Temperature with Fitted GLM Logistic Regression Line")
points(Temp,male/(male+female),pch=16, col="red")

于 2014-03-21T21:50:55.577 回答