2

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? pls

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
phil
  • 75
  • 7

1 Answers1

4

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)

enter image description here

The OP's version of this plot is

enter image description here

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).

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Oh, Thanks a lot for this quick help! I run the code, it worked. However, the regression line I obtained is a linear line, not like the line you obtained. I don't know how to uplpoad pic in comment, and I googled and found the pic in this website is quite similar as my pic. http://www.bzst.com/2012/05/linear-regression-for-binary-outcome-is.html. – phil Apr 17 '17 at 15:09
  • hard to say, but your logistic regression curve will be *approximately* linear if the predicted probabilities are (approximately) between 0.3 and 0.7. You can upload images to imgur if you like and include the link in your comment, *or* edit your question ... – Ben Bolker Apr 17 '17 at 15:24
  • Sorry, I can not upload two pics in my question, hence, I used my google drive to store the pic:https://drive.google.com/file/d/0B5VHYG-mRtCUTk1qdTJlZk9mYkE/view?usp=sharing. Many thanks! – phil Apr 17 '17 at 16:09
  • Your plot looks fine. – Ben Bolker Apr 17 '17 at 18:01
  • Great help! Thanks a lot, Ben! Sorry for the missing of X axis. It is the same as your plot, from 0 to 1. I got what your meaning, and thanks again for the help with the question and the edits of the question! – phil Apr 17 '17 at 19:11