【发布时间】:2016-07-26 02:49:04
【问题描述】:
我想编写代码来绘制我的逻辑回归模型,即“S”形逻辑曲线。既然我有两个独立的协变量,那怎么办?我附上了我的数据集和我的模型的代码。先感谢您。
239 0.72 1
324.6 0.83 1
331.8 0.95 1
334.3 0.83 1
259.7 0.89 1
212.3 0.88 1
204.7 0.65 1
253.86 0.75 1
258.94 0.85 1
329.66 0.95 0
469.68 1.46 0
459.74 1.11 0
293.2 0.64 0
297.88 0.98 0
267.9 0.82 0
374.1 1.29 0
333.62 0.74 0
dat <- read.table("data.txt")
colnames(dat)<-c("press","v","gender")
# logostic regression
dat$gender <- factor(dat$gender)
mylogit<- glm(gender~press+v,data=dat,family="binomial")
summary(mylogit)
######## the code below are irrelevant to making plot, ignore if you want
mylogit$fitted.values
newdat <- data.frame(t(c(300,0.1)))
colnames(newdat)<-c("press","v")
# this is your new dataset, we name it as "newdat"
pred <- predict(mylogit,newdata = newdat,type="response")
pred # the probability of being in class 1 will stored in this object
pred <- predict(mylogit,newdata = dat,type="response")
pred # the probability of being in class 1 will stored in this object
# accuracy
dat$pred <- 0
factor(dat$pred)
dat$pred[which(pred>0.5)] <- 1
table(dat$gender,dat$pred)
【问题讨论】:
-
是的 - 我想绘制逻辑曲线
-
应该是这样的,但它显示错误。我不知道怎么处理。
-
绘图(dat$press,dat$gender) 曲线(predict(mylogit,newdata=newdat,type="resp"),add=TRUE)
-
好的,我想用 3D 绘制它,你能告诉我怎么做吗,因为我还是 R 的初学者。据我所知,它应该绘制预测变量和逻辑模型系数。我知道它有两个数字。你能帮我画一下吗?我之前提供的代码是否也不适用于您?
标签: r plot regression logistic-regression glm