-
Notifications
You must be signed in to change notification settings - Fork 0
/
hglmbc2_vignette.Rmd
60 lines (46 loc) · 1.9 KB
/
hglmbc2_vignette.Rmd
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: "Calibrated h-likelihood with bias correction in SAE (hglmbc2) vignette"
author: Nirosha Rathnayake^[University of Nebraska Medical Center, niro.uno@gmail.com, https://niroshar.github.io/My-Profile/]
# output: rmarkdown::html_document
output:
html_document:
vignette: >
%\VignetteIndexEntry{hglmbc2_vignette}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(hglmbc2)
```
The proposed `calibrated h-likelihood with bias correction' approach is currently limited to GLM family distributions where a response variable whose conditional distribution of $y|u$ belongs to exponential family and the random effect $u\sim N(0,\sigma^2)$. The algorithm consists of two main key components:
1. A linear predictor: $\eta_i=\sum_{i=1}^n x_i\beta_i$,
2. A link function: $\eta_i = g(\mu_i)$,
The list of components in each GLM family distribution in R is illustrated in an object of class, `family`(run `?family` in R console for more details). As an example, the code below shows the constituent parts for the binomial GLM, which is what is used to fit linear logistic regression:
```{r}
b.family <- binomial()
class(b.family)
names(b.family)
p.family <- poisson()
p.family
b.family
```
**Example: Binomial-Normal HGLM (Mixed Logit Model) with Bias Correction**
`Binomial-Normal HGLM` is also known as the `mixed logit` model in GLM family with the binary response variable and the random effect $u\sim N(0,\sigma^2)$.
```{r hBino, echo=TRUE}
library(hglmbc2)
## basic example code
data <- eversmoke
mformula <- "smoke_ever ~ as.factor(age) + as.factor(gender) + as.factor(race) + as.factor(year) + povt_rate"
dom <- "county"
y.family <- "binomial"
rand.family <- "gaussian"
## Fit the model
# hglmbc.fit <- hglmbc(data=eversmoke, mformula, dom = "county", y.family=binomial)
# hglmbc.fit$summary
```