I used the phylolm package to do phylogenetic comparative analysis. As my response variable is binary data (ones and zeros), I used phylogenetic logistic regression.
How do I plot the output of phyloglm
? I found a similar question here, but I can't understand the reply. could you please provide some advice about how to plot the results, as shown here?
Using the example from ?phyloglm
:
library(ape)
library(phylolm)
set.seed(123456)
tre = rtree(50)
x = rTrait(n=1,phy=tre)
X = cbind(rep(1,50),x)
y = rbinTrait(n=1,phy=tre, beta=c(-1,0.5), alpha=1 ,X=X)
dat = data.frame(trait01 = y, predictor = x)
fit = phyloglm(trait01~predictor,phy=tre,data=dat,boot=100)
Plot (jittered) data and response (plogis()
is the logistic function.
The predicted value is logistic(a+b*x)
; we use curve()
with
add=TRUE
to draw the line)
par(las=1,bty="l") ## cosmetic
plot(x,jitter(y,factor=0,amount=0.02),
xlab="trait",ylab="response",xlim=c(-3.5,3.5))
cc <- coef(fit)
curve(plogis(cc[1]+cc[2]*x),col="red",add=TRUE)
The OP's version of this plot is
which (although we can't see the y-axis scale) is perfectly consistent with a logistic fit, being approximately linear across the intermediate range of predicted values (there is a hint of deceleration at the upper end of the curve).