caterinap / PowerC

PowerC is a package of R functions to perform power analysis in comparative methods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PowerC

PowerC is a a group of R functions to perform sampling effort analysis in comparative methods

###Functions:

sampling.pgls - Simple sampling effort analysis for PGLS linear regression
influential.pgls - Simple (leave-one-out deletion) diagnostics for PGLS linear regression
plot.power.pgls - Plot results from sampling.pgls and influential.pgls

###Examples: First copy and run these functions:
1. sampling.pgls
2. influential.pgls
3. plot.power.pgls

Required Packages:

library(caper);library(phytools);library("phylolm")

Simulating data and phylogeny:

set.seed(111)
N <- 50 # Number of species
### Simulating tree
tree<-pbtree(n=N)    
### Simulating response variable with phylogenetic signal
y <- rTrait(n=1, tree, model=c("lambda"),parameters=list(lambda=.8))  
### Simulating explanatory variable
x <- y + rnorm(N,mean(y),1)     
### Including Species names
sp <- tree$tip.label               
regre <- data.frame(sp,y,x)   
### Organizing comparative data for pgls:
c.data <- comparative.data(data=regre,phy=tree,vcv=T,vcv.dim=3,names.col="sp")

Fitting regressions:

### Linear regression (PGLS):
mod0 <- pgls(y ~x, data=c.data,"ML")
summary(mod0)

Regression Plots:

plot(y ~ x,c.data$data,pch=16)
abline(mod0,col="red",lwd=3)

Performing Sensitive Analysis: sampling.pgls

samp1 <- sampling.pgls(y~x,data=regre,phy=tree,times=10,breaks=seq(.1,.9,.1),lambda="ML",names.col="sp")
### You can also specify the number of replicates per break interval:
samp2 <- sampling.pgls(y~x,data=regre,phy=tree,times=50,breaks=c(.1,.5,.9),lambda="ML",names.col="sp")

Performing influential analysis: influential.pgls

### Example: influence.pgls
influ1 <- influence.pgls(y ~ x,data=regre,phy=tree,lambda="ML")
### Estimates values:
influ1$estimates
### Most influential species:
influ1[[5]]

Visualizing Results:

plot.power.pgls(samp1,method="sampling")
plot.power.pgls(samp2,method="sampling")
plot.power.pgls(influ1,method="influential")

About

PowerC is a package of R functions to perform power analysis in comparative methods

License:GNU General Public License v2.0


Languages

Language:R 100.0%