Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 叠加物流拟合线_R_Curve Fitting_Logistic Regression - Fatal编程技术网

R 叠加物流拟合线

R 叠加物流拟合线,r,curve-fitting,logistic-regression,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) summa

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

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) 

有hlp吗?

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

逻辑回归对事件发生的概率进行建模。因此,在您的案例中,您正在根据三种不同的
温度下
男性比例的数据对
男性的概率进行建模,例如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")

Temp您的帖子非常有用。但是,我相信您可以叠加曲线,而不是最佳拟合线。我遇到一个代码,它在下面的链接上绘制了一条曲线。我也试过下面的代码,(curve(predict(Temp,male=x,type=“resp”),add=TRUE)),但它给了我一个错误。我承认,这段代码特别容易混淆,尤其是在表格中读取。我只是试着用不同的方法来解决这个问题。我用下面的代码来叠加曲线###问题1临时工
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")