我想創建基於二進制數據作爲因變量(直接離開= 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()
僅爲整個數據集提供一個值。 因此,我想創建兩個適合線條的圖形:每個處理一個。有沒有可能做到這一點,如果是的話如何?
我是否真的需要在我的模型中包含時間和持續時間以構建任意擬合線?無論如何,合適的線條不會出現在劇情中,我不知道爲什麼,因爲我使用了這裏發佈的確切線條。 – Maxi
由於上面貼出的代碼不起作用(擬合線不出現在圖中),我使用了'ggplot(data_animal,aes(x = Time,y = DirLea,shape = Treat))+ geom_point()+ geom_smooth (method =「glm」)'導致[在此圖中](https://dl.dropboxusercontent.com/u/38035375/ggplot_Treatment.jpg)。即使它不是線性迴歸,也可以使用它嗎? – Maxi
我無法檢查上述工作是否因爲您沒有足夠的數據集供我實際運行代碼。至於第一個問題,我不清楚你的合適線路有什麼統計或分析目的。 – crowding