Description Usage Arguments Author(s) See Also Examples
Using standard formula notation from glmer
(lme4
), defines a Stan model (rstan
) and optionally samples from the posterior. Can optionally compute WAIC. Supports model families: "gaussian", "binomial", "poisson", "negative binomial", "beta", "gamma", "lognormal", "beta-binomial", "ordered",and "zero-inflated poisson, negative binomial and gamma".
1 2 3 4 5 6 7 | glmmstan(formula_str, data, family="gaussian",
center=FALSE, slice = NULL, offset=NULL,
codeonly=FALSE, dataonly=FALSE, modelonly=FALSE,
cauchy=2.5, lkj_corr=2,
stancode=NULL, standata=NULL, stanmodel=NULL, stanfile=NULL, stanfit=NULL,
parallel=FALSE, cores=NULL,
iter=2000, warmup = NULL, chains= 2, thin=1)
|
formula_str |
Model formula or list of formulas, using |
data |
Data frame or list. |
family |
Model family name or list of names for outcome(s). Valid choices are: "gaussian", "binomial" (logit link), "poisson" (log link), "nbinomial" (log link),"gamma" (log link), "beta" (logitlinks), "lognormal" (log link),"ordered" (cumulative logit),"beta-binomial"(logit link),"zipoisson"(log link),"zinbinomial"(log link),"zigamma"(log link). |
center |
If TRUE, center the independent variables(set means=0). |
offset |
Input offset term in model(only "poisson","nbinomial"). |
codeonly |
If TRUE, output only stan code. |
dataonly |
If TRUE, output only dataset for stan. |
modelonly |
If TRUE, output only compiled stanmodel. |
cauchy |
Scale parameters of cauchy distribution which is prior distribution of variance components. |
parallel |
If TRUE, run the stanmodel in parallel using doparallel package. |
cores |
Number of cores to use when executing the chains in parallel. |
iter |
rstan parameter: total number of samples, including warmup. |
warmup |
rstan parameter: number of adaptation samples. |
chains |
rstan parameter: number of chains. |
thin |
rstan parameter: A positive integer specifying the period for saving sample. |
Hiroshi Shimizu
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 | data(baseball)
#"gaussian"
fit1 <- glmmstan(salary_log~1,data=baseball,family="gaussian")
output_result(fit1) #output glmm result
output_stan(fit1) #output summarized stan result (including rhat index)
print(fit1) #output stan result (same print() in rstan)
#"lognormal" with random effect
fit2 <- glmmstan(salary~HR+(1+HR|team),data=baseball,family="lognormal")
output_result(fit2)$WAIC #output only WAIC
#"negative binomial" with offset term
fit3 <- glmmstan(HR~1,data=baseball,family="nbinomial",offset="ATbats")
output_result(fit3)$beta #output only coefficients and scale parameters
#"ordered" with centering indipendent variables
fit4 <- glmmstan(Cluster~salary,data=baseball,family="ordered",center=TRUE)
output_result(fit4)
output_code(fit4) #confirm the stan code
#output only stan code, datase, and stan model
code1 <- glmmstan(HR~1+(1|player),data=baseball,family="poisson",codeonly=TRUE)
dataset1 <- glmmstan(HR~1+(1|player),data=baseball,family="poisson",dataonly=TRUE)
model1 <- glmmstan(HR~1+(1|player),data=baseball,family="poisson",modelonly=TRUE)
fit5 <- stan(model_code=code1, data=dataset1)
fit6 <- sampling(model1,data=dataset1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.