## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6,
  fig.height = 4,
  eval = requireNamespace("plm", quietly = TRUE)
)

## ----setup--------------------------------------------------------------------
library(panglm)
data(Grunfeld, package = "plm")

## ----pooled-------------------------------------------------------------------
fit_pool <- panglm(
  inv ~ value + capital,
  data = Grunfeld,
  index = c("firm", "year"),
  model = "pooling",
  family = "gaussian"
)
coef(fit_pool)

## ----pooled-cluster-----------------------------------------------------------
sqrt(diag(vcov(fit_pool, type = "cluster")))

## ----within-gaussian----------------------------------------------------------
fit_fe <- panglm(
  inv ~ value + capital,
  data = Grunfeld,
  index = c("firm", "year"),
  model = "within",
  family = "gaussian"
)
coef(fit_fe)

## ----random-gaussian----------------------------------------------------------
fit_re <- panglm(
  inv ~ value + capital,
  data = Grunfeld,
  index = c("firm", "year"),
  model = "random",
  family = "gaussian"
)
coef(fit_re)

## ----inference----------------------------------------------------------------
vcov(fit_fe, type = "cluster")
confint(fit_fe)

## ----plots, fig.alt = "Coefficient estimates with confidence intervals"-------
plot(fit_fe, which = "coefficients")

## ----hausman------------------------------------------------------------------
panglm_hausman(fit_fe, fit_re)

## ----hurdle-------------------------------------------------------------------
data(copd)
fit_hurdle <- panglm_hurdle(
  exacerbations ~ crp,
  data = copd,
  index = c("id", "visit"),
  count_family = "negbin"
)
plot(fit_hurdle)

