mixing: Mixing plot

Description Usage Arguments Author(s) Examples

View source: R/mixing.R

Description

This function draws mixing plot for the estimated parameters, the parameter's general means, and the sigma.

Usage

1
mixing(x, toplot = "paramX", param = c(1, 1), add = FALSE, ...)

Arguments

x

Object of class HMSC

toplot

A character string defining whether the mixing plot should be drawn for parameter in "paramX", "means", or "sigma". Any unambiguous variation of wording used in this argument is accepted.

param

A vector of one ("means" when using hmscH, "RandomVar", or ) or two integer ("paramX","paramTr", "paramRandom" or "sigma") defining for which parameter the mixing plot should be drawn.

add

Logical. Whether a new plot (FALSE) should be drawn or the mixing plot should be drawn within another plot.

...

Graphical arguments passed to this function.

Author(s)

F. Guillaume Blanchet

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
desc<-cbind(1,scale(1:50),scale(1:50)^2)
dataBase<-communitySimulH(desc,nsp=20)

#=================================
### Formatting data and parameters
#=================================
formdata<-as.HMSCdata(dataBase$data$Y,desc,Ypattern="sp",interceptX=FALSE)
formparam<-as.HMSCparam(formdata,dataBase$param$param,means=dataBase$param$means,sigma=dataBase$param$sigma)
formpriors<-as.HMSCprior(formparam,rep(0,length(formparam$means)),0,length(formparam$means),diag(length(formparam$means)))

#===========================================================================================================
### Building model using a linear modelling approach (currently 2000 iterations takes about 1 minute to run)
#===========================================================================================================
modelLinear<-hmscH(formdata,formparam,formpriors,niter=200,nburn=100)

#___________________
#### Community Sigma
#___________________
par(mfrow=c(3,3),mar=c(1,3,3,1))
for(i in 1:3){
	for(j in 1:3){
		mixing(modelLinear,toplot="sigma",param=c(i,j),col="red",xlab="Sites",ylab="Sigma",las=1)
		abline(h=formparam$sigma[i,j],col=c("red"),lwd=3)
		title(paste("Community Sigma",i,"-",j))
	}
}

#__________________
### Community means
#__________________
mixing(modelLinear,toplot="means",param=1,ylim=range(modelLinear$model$means),xlab="Sites",ylab="Means",las=1)
title("Community means")
mixing(modelLinear,toplot="means",param=2,add=TRUE,col="blue",xlab="Sites",ylab="Means",las=1)
mixing(modelLinear,toplot="means",param=3,add=TRUE,col="red",xlab="Sites",ylab="Means",las=1)
abline(h=formparam$means,col=c("black","blue","red"),lwd=3)

#_____________________________
### Parameter for each species 
#_____________________________
par(mfrow=c(5,4),mar=c(1,3,2,1))
for(i in 1:20){
	mixing(modelLinear,toplot="paramX",param=c(i,1),ylim=range(modelLinear$model$paramX[i,,]),xlab="Sites",ylab="paramX",las=1,xaxt="n")
	title(paste("Species",i))
	mixing(modelLinear,toplot="paramX",param=c(i,2),add=TRUE,col="blue")
	mixing(modelLinear,toplot="paramX",param=c(i,3),add=TRUE,col="red")
	abline(h=formparam$paramX[i,],col=c("black","blue","red"),lwd=3)
}

HMSC documentation built on May 2, 2019, 6:53 p.m.