Introduction

knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )

Package Overview

Often the first problem in understanding the generalized linear model in a practical way is finding good data. Common problems include finding data with a small number of rows, the response variable does not follow a family in the glm framework, or the data is messy and needs a lot of work before statistical analysis can begin. This package alleviates all of these by allowing you to create the data you want. With data in hand, you can empirically answer any question you have.

The goal of this package is to strike a balance between mathematical flexibility and simplicity of use. You can control the sample size, link function, number of unrelated variables, and dispersion for continuous distributions. Default values are carefully chosen so data can be generated without thinking about mathematical connections between weights, links, and distributions.

Below will demonstrate how to use this package to answer questions about the glm framework.

Question 1: Is A Sample Size Of 200 Enough To Get Close Estimates Of The True Weights?

library(GlmSimulatoR) library(ggplot2) set.seed(1) simdata <- simulate_gaussian(N = 200, weights = c(1, 2, 3)) glmModel <- glm(Y ~ X1 + X2 + X3, data = simdata, family = gaussian(link = "identity")) summary(glmModel) rm(glmModel)

In the above, we see the estimates are close to the weights argument. The mathematics behind the generalized linear model worked well.

library(GlmSimulatoR) library(ggplot2) set.seed(1) simdata <- simulate_gaussian(link = "identity") linearModel <- lm(Y ~ X1 + X2 + X3, data = simdata) glmModel <- glm(Y ~ X1 + X2 + X3, data = simdata, family = gaussian(link = "identity")) summary(linearModel) summary(glmModel) rm(simdata, linearModel, glmModel)

In the above, we see the coefficients and standard errors are the same between the linear model and the generalized linear model. This confirms the linear model is identical to a generalized linear model with gaussian family and identity link.