叠加物流线

时间:2014-03-21 21:18:57

标签: r curve-fitting logistic-regression

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

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") 

任何hlp?

1 个答案:

答案 0 :(得分:1)

您的代码有点令人困惑,所以这可能不是您的目标。

Logistic回归模拟事件发生的概率。因此,在您的情况下,您基于数据给males的概率建模,该数据给出males在三个不同Temp的比例,例如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") 。 0 / 10,8 / 12(.66)和8/10(0.8)。因此,为了将模型与数据进行比较,您必须绘制预测响应与男性分数。

{{1}}