# Title : ExploreGLM.R
# Objective : Explorevia GLM
# Created by: greyhypotheses
# Created on: 31/03/2022
#' Modelling via glm(.)
#'
#' @param nerve: The data frame of the nerve data set
#'
ExploreGLM <- function (nerve) {
# The residual deviance measures how well a response variable can be predicted by a model
# with p predictor variables →
#
# Null Hypothesis: The model fits the data well,
# p.value = 1 - pchisqr(residual deviance, residual degrees of freedom, lower.tail = TRUE)
# = pchisqr(residual deviance, residual degrees of freedom, lower.tail = FALSE)
# Alternative Hypothesis: Otherwise
# ... formula set-up: [success, failure] ~ variables
model <- glm( cbind(reactionCount, 15 - reactionCount) ~ painScoreStd,
family = binomial(link = 'logit'), data = nerve )
# ... a significant relationship between pain score and reaction count
summary(model)
anova(model)
# ... but a better model is required; the p.value suggests evidence against the null hypothesis
estimates <- NULL
estimates$residual.deviance <- model$deviance
estimates$residual.freedom <- model$df.residual
estimates$p.value <- 1 - pchisq(q = estimates$residual.deviance,
df = estimates$residual.freedom, lower.tail = TRUE)
estimates$p.value <- pchisq(q = estimates$residual.deviance,
df = estimates$residual.freedom, lower.tail = FALSE)
return(list(model = model, estimates = estimates))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.