These functions are used to format the data, parameters, and priors to object classes "HMSC".

1 2 3 | ```
as.HMSCdata(Y, X,Tr=NULL,Random=NULL, Ypattern = NULL,scaleX=TRUE,scaleTr=TRUE,interceptX=TRUE,interceptTr=TRUE)
as.HMSCparam(HMSCdata,paramX,paramTr=NULL,paramRandom=NULL, means=NULL, sigma,RandomVar=NULL,RandomCommSp=NULL)
as.HMSCprior(HMSCparam,means0,kappa0,nu0,Lambda0,sigma0=NULL,priorRandom=NULL)
``` |

`Y` |
A matrix or a data.frame where each column is a species. |

`X` |
A matrix or a data.frame where each column is a descriptor of the sites. |

`Tr` |
A matrix or a data.frame where each row is a trait characterizing all species. |

`Random` |
A factor defining a random effect on the samples. |

`Ypattern` |
A character string defining a regular pattern placed in front of the names of each species. |

`scaleX` |
Logical. Whether the columns of X should be centred and divided by the standard deviation. Default is TRUE. |

`scaleTr` |
Logical. Whether the columns of Tr should be centred and divided by the standard deviation. Default is TRUE. |

`interceptX` |
Logical. Whether a column of 1s should be added to X. Default is TRUE. |

`interceptTr` |
Logical. Whether a column of 1s should be added to Tr. Default is TRUE. |

`HMSCdata` |
An object of the class |

`paramX` |
A matrix of model parameters defining how each species (rows) is characterized by each descriptors (columns). |

`paramTr` |
A matrix of model parameters defining how each descriptors (rows) characterizes species traits (columns). |

`paramRandom` |
A matrix of model parameters defining how each level of the random effect (rows) characterizes species (columns). |

`means` |
Vector of the regression parameter averaged over the response variables. This vectors should have the same length as the number of columns in |

`sigma` |
Symmetric covariance matrix. Each dimension of this matrix should be equal to the number of values in |

`RandomVar` |
Scalar defining the within group variance in |

`RandomCommSp` |
A scalar defining how the random effect influence species independently (0) and on as a community (1). |

`HMSCparam` |
An object of the class |

`means0` |
Vector of the prior of |

`kappa0` |
Numeric. Prior for kappa. (See details). |

`nu0` |
Numeric. Prior for nu. (See details). |

`Lambda0` |
A matrix defining the prior for Lambda. (See details). |

`sigma0` |
A value defining the prior for the calculation of the normal likelihood. (See details). |

`priorRandom` |
A vector of length 2 defining the mean and the standard deviation of the prior for |

Although it may seem cumbersome for all variables to have names, it is essential for the analyses carried out with formula. In that instance, it was decided to make names mandatory for all variables, parameters, and priors when using this package. This is why all data, parameters, and priors need to be formated by these functions before any analyses are carried out with `HMSC`

.

Except for `Random`

, which only takes a factor, only numerical variables should be included as data for the analyses performed within this package. All other types of variables have not yet been implemented.

The output of `communitySimulH`

is formated using these functions to ensure that they can be used right away with the different analytical function of this package.

The priors `mean0`

, `kappa0`

, `nu0`

and `Lambda0`

make it possible to directly sample the conditional distribution of a multivariate normal distribution with a known variance without having to go through an Markov chain Monte Carlo procedure (Gelman et al. 2013). All other priors are necessary for the calculations of different likelihoods such as the likelihood for the negative binomial, normal, or gamma distributions (### These likelihood are not yet implemented ###).

An object of the class `HMSCdata`

is returned by `as.HMSCdata`

.
An object of the class `HMSCparam`

is returned by `as.HMSCparam`

.
An object of the class `HMSCprior`

is returned by `as.HMSCprior`

.

All of these objects present the same output data as the input. The HMSCdata class has the `Ypattern`

as an attribute.

These functions will likely get more refined with time and with the new models implemented in the package.

F. Guillaume Blanchet

1 2 3 4 5 6 7 8 9 10 11 12 13 | ```
### Generate data
desc<-cbind(1,scale(1:50),scale(1:50)^2)
dataBase<-communitySimulH(desc,nsp=30)
### Formatting wrong way
formdata<-as.HMSCdata(dataBase$data$Y,desc,interceptX=FALSE)
str(formdata) # Note the columns names in formdata$Y
## Not run: formparam<-as.HMSCparam(formdata,dataBase$param$param,dataBase$param$means,dataBase$param$sigma) # Error message
### Formatting good way
formdata<-as.HMSCdata(dataBase$data$Y,desc,Ypattern="sp",interceptX=FALSE)
formparam<-as.HMSCparam(formdata,dataBase$param$paramX,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)))
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.