MCLogLin {ltable} | R Documentation |
Function MCLogLin
Description
Performs log-linear analyses for constructed tabulated data based on Gibbs sampler with NB2 posterior marginal distribution for counts
Usage
MCLogLin(formula, data, offset, contrasts=NULL, XLB=-100, XUB=100, a=0.1, b=0.1,
DIC=FALSE, pcov=FALSE, draw=10000, burnin=3000 )
Arguments
formula |
a symbolic description of the model to be fit. |
data |
name of the data set; object of data.frame class |
offset |
variable in the data set to be used as offset. |
contrasts |
serves to choose types of contrasts to study effects of factors, the same with glm{stats}), orthogonal polynomials by default |
XLB |
the vector of smallest possible values of regression effects betas; can be number if pertains to all betas. |
XUB |
the vector of largest possible values of regression effects betas; can be number if pertains to all betas. |
a |
the value of shape parameter of gamma distributed inverce dispersion parameter (phi), i.e., phi~Ga(a,b), so that mean(phi)=a/b and var(phi)=a/b^2 |
b |
the value of rate (1/scale) parameter of gamma distributed inverce dispersion parameter (phi), i.e., phi~Ga(a,b), so that mean(phi)=a/b and var(phi)=a/b^2 |
DIC |
requests print of deviance information criteria and its components |
pcov |
requests print of covariance and correlation matricies of the model parameters |
draw |
indicates requested number of samples |
burnin |
indicates requested number of initial samples to discard |
Details
Performs log-linear modelling with supplied data by using Gibbs sampler.
Printing output includes standard table of parameters estimates, goodness of fit indicators, analysis of residuals. On the prompt it prints the deviance information criteria with its components as well as covariance and correlation matricies of the model parameters. By using parameter (offset) one can model risks and relative risks instead of counts.
Value
returns a matrix with columns of chains of sampled values of model parameters (expected counts, regression coefficients, inverce dispersion parameter) to be studied by MCMC facilitating packages (e.g., coda, mcmc, mcmcplot, etc.)
Note
Function provides better conditioned variance matrix estimates against function stats::glm, which is particular important for high order effects and power analysis. Particularly suggestive is to check the model fit first. Jacobian reciprocal condition number near zero indicates solution instability. If chisq/n >> 1, the error estimates obtained from the covariance matrix will be too small and should be multiplied by square root of chisq/dof. Poor fit will result from the use of an inappropriate model and jeopardizes the validity of power analysis.
It's recommended to keep difference between pars draw and burnin at least 3000.
Author(s)
Ocheredko Oleksandr Ocheredko@yahoo.com
See Also
Examples
require(ltable)
data(tdata, package="ltable")
## For better illustration You should increase draw and burnin pars
res1<-MCLogLin(Counts~smoker +contraceptive +tromb +
contraceptive*tromb, data=tdata, draw=1500, burnin=500)
data(iris)
iriscut<-with(iris, data.frame(PL=cut(Petal.Length,3),
PW=cut(Petal.Width,3)))
irist<-table_f(iriscut,"PL,PW")
irisd<-tableToData(irist, ordered="PL,PW")
res2<-ltable::MCLogLin(Counts~PW+PL+PW*PL, DIC=TRUE, data=irisd,
draw=1500, burnin=500)