我正在尝试基于二进制数据作为因变量(直接离开 = 0 或 1)创建逻辑回归图。自变量是连续数据(危险提示的持续时间)、计数数据(危险提示出现的时间)和分类数据(治疗:蔗糖或章鱼胺):
AnimalID Time Duration Treatment Daytime DirectLeave
1 1039.6 1.1 sucrose mornings 1
2 1116.5 7.6 OA mornings 0
3 359.9 2.4 sucrose afternoon 0
4 594.2 27.3 OA afternoon 1
5 951.4 10.5 OA mornings 1
6 612.4 3.8 sucrose afternoon 0
到目前为止,我能够为整个数据集创建两个带有一条拟合线的图表(下图):
library(car)
data_animal <- read.table("DirLeave_DurSorted.txt",header=T)
# Plot for relationship between immediate leave of animal and the time of danger cue presentation
pufftimegraph<-glm(DirLea ~ Time , family=binomial(link=logit), data=data_animal)
summary(pufftimegraph)
Anova(pufftimegraph)
data_animal$fitted<-pufftimegraph$fitted
dummy<-(data_animal$Time)
dummy<-sort(dummy)
print(dummy)
plot(data_animal$DirLea~data_animal$Time, xlab ="Time of the presentation of the danger cue", ylab="Proportion of wasps leaving the patch")
lines(data_animal$Time,(1/(1+(1/exp(0.0011188*data_Maxi$Time+-0.0174130)))), col="black")
# Plot for relationship between immediate leave of animal and duration of danger cue
durgraph<-glm(DirLea ~ Dur , family=binomial(link=logit), data=data_animal)
summary(durgraph)
Anova(durgraph)
data_animal$fitteddur<-durgraph$fitted
print(data_animal$fitteddur)
plot(data_animal$DirLea~data_animal$Dur, xlab ="Duration of the danger cue [s]", ylab="Proportion of wasps leaving the patch")
lines(data_animal$Dur,(1/(1+(1/exp(0.15020*data_animal$Dur+-1.00618)))), col="black")
然而,我研究的目的是展示两种治疗方法之间的差异。我知道我需要两个类别(即蔗糖和章鱼胺)的斜率和截距值,但Anova()
只为整个数据集提供一个值。所以,我想用两条拟合线创建两个图表:每个处理一个。是否有可能做到这一点,如果可以,怎么做?