Code Monkey home page Code Monkey logo

glmmstan's Introduction

glmmstan

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".

Install

If you have not install RStan, please read RStan document and install it.

And you need devtools to install glmmstan from GitHub.

install.packages("devtools")

After install these packages, excute the following in R:

library(devtools)
install_github("norimune/glmmstan")

Example

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)

#intra-class correlations
model <- iccmodel()
y <- subset(baseball,select=c(HR,HIT))
fit7 <- iccstan(y,baseball$team,model=model)
output_icc(fit7)

glmmstan's People

Contributors

norimune avatar kazutan avatar

Watchers

James Cloos avatar Koji E. Kosugi avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.