# loglikelihood: Log-likelihood of a regression model In HMSC: Hierarchical modelling of species community

## Description

These functions calculate different log-likelihoods in the context of regression analyses. The different log-likelihoods are all calculated by using the function loglikelihood. Depending on the information that serves as input in the function different log-likelihood will be calculated. In the usage section, the first two ways to use loglikelihood allows the user to calculate the log-likelihood of the mean regression parameters whereas the third way calculates the log-likelihood of the sigma (the models variance-covariance matrix).

## Usage

 1 2 3 4 5 6 ## S3 method for class 'formula' loglikelihood(formula,paramX,data,likelihoodtype="logit",..., prior) ## Default S3 method: loglikelihood(y, X, paramX,Random=NULL,paramRandom=NULL, likelihoodtype = "logit",..., prior) ## S3 method for class 'matrix' loglikelihood(mat,param,means,likelihoodtype="sigma",...) 

## Arguments

 formula Model formula. The left side presents the response matrix and the right side gives the descriptors with their parameters. (See details) y Vector defining a single response variable. X Matrix where the descriptors are columns. paramX Vector of regression parameters associated to the fixed effect (X). param Vector of regression parameters. (May potentially change !) Random Matrix defining the random effect. Each column contains either 1s (effect) or 0s (absence of effect) of the random effect. paramRandom Vector of regression parameters associated to the random effect. data A data.frame including the variables used to calculate the log-likelihood. mat A symmetric positive definite matrix. means Vector of the regression parameter averaged over the response variables. This vectors should have the same length as param. likelihoodtype Character string defining how the likelihood should be calculated. Any unambiguous variation of wording used in this argument is accepted. (See details) ... Parameters passed to other functions. prior Numeric. A value defining a prior for specific likelihood functions (e.g. Normal likelihood). (See details)

## Details

The formula was designed so that it is necessary to include the parameters and the descriptors. This function is thus capable of carrying out non-linear regression analyses.

The prior is used only in likelihood functions that require additional prior information for the estimation of the likelihood. For example, when estimating the likelihood of the mean of a normal distribution, prior information on the variance of the normal distribution is required.

So far, the following log-likelihood have been implemented. In the formulas bellow, the inverse link functions are represented by "l", the model is presented by "m", the response variable (typically a single species) is defined by "y" and "n" defines the number of samples:

 logit sum(log((l*y)+((1-l)*(1-y)))) Poisson sum(log(l)*y)-n*l normal -1/(2*sigma^2) * sum((y-model)^2) sigma -(β_i -\bar{β_j}_i) σ^{-i}(β_i -\bar{β_j}_i)/2 R -(p/2)*log(det(R))-(sum_{i=1}^p W_i R^{-1} W_i)(2)-(p+1)/2*log(det(W))-sum(diag(W^{-1}))/2

For the sigma and R likelihood, the input needs to be a matrix. Note that the R likelihood used is designed for each non-diagonal values in the matrix to follow a uniform distribution ranging from -1 to 1.

## Value

A vector of log-likelihood values.

## Note

These functions are meant to be used within scam.

## Author(s)

F. Guillaume Blanchet

ilogit