Title: | Test Model Fit with Simulation |
---|---|
Description: | Simulates data from model objects (e.g., from lm(), glm()), and plots this along with the original data to compare how well the simulated data matches the original data to determine model fit. |
Authors: | James Green [aut, cre] |
Maintainer: | James Green <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-11-13 03:43:15 UTC |
Source: | https://github.com/cran/simfit |
Fit Simulated Data to a Model.
pred.fit(model, xpred = NULL, ci = 0.95, npoints = "same")
pred.fit(model, xpred = NULL, ci = 0.95, npoints = "same")
model |
a model object, from (eg) lm |
xpred |
the predictor for the x axis on the graph |
ci |
confidence interval for fit curve (defaults to 0.95) |
npoints |
number of data points for fit line. Either specify a number, or "same" will return a simulation of the same size as the original dataset. |
predicted data
## Anwar M, Green JA, Norris P, et al ## Prospective daily diary study reporting of any and all symptoms in healthy ## adults in Pakistan: prevalence and #' response ## BMJ Open 2017;7:e014998 data(symptom) glm.symptom <- glm(actual_help_days ~ symp_days_reported, family = "poisson", data = symptom) pred.fit(glm.symptom)
## Anwar M, Green JA, Norris P, et al ## Prospective daily diary study reporting of any and all symptoms in healthy ## adults in Pakistan: prevalence and #' response ## BMJ Open 2017;7:e014998 data(symptom) glm.symptom <- glm(actual_help_days ~ symp_days_reported, family = "poisson", data = symptom) pred.fit(glm.symptom)
Add model fit line (with SE) to GLM models (Poisson, negative binomial etc)
pred.plot(model, xpred = NULL, ci = 0.95)
pred.plot(model, xpred = NULL, ci = 0.95)
model |
a model object, from (eg) lm glm |
xpred |
the predictor to be plotted on the x axis |
ci |
value for confidence interval (defaults to 0.95) |
ggplot object with fit line
#' ## Anwar M, Green JA, Norris P, et al ## Prospective daily diary study reporting of any and all symptoms in healthy ## adults in Pakistan: prevalence and #' response ## BMJ Open 2017;7:e014998 data(symptom) glm.symptom <- glm(actual_help_days ~ symp_days_reported, family = "poisson", data = symptom) pred.plot(glm.symptom)
#' ## Anwar M, Green JA, Norris P, et al ## Prospective daily diary study reporting of any and all symptoms in healthy ## adults in Pakistan: prevalence and #' response ## BMJ Open 2017;7:e014998 data(symptom) glm.symptom <- glm(actual_help_days ~ symp_days_reported, family = "poisson", data = symptom) pred.plot(glm.symptom)
Plot simulated data from a GLM model
sim.plot( model, xpred = NULL, seed = NULL, fit.line = TRUE, ci = 0.95, npoints = "same", orig_jitter = 0.1, sim_jitter = 0.1 )
sim.plot( model, xpred = NULL, seed = NULL, fit.line = TRUE, ci = 0.95, npoints = "same", orig_jitter = 0.1, sim_jitter = 0.1 )
model |
a model object, from (eg) lm glm (Poisson, Negative binomial) |
xpred |
the predictor to be plotted on the x axis |
seed |
random seed so that simulation results are replicable |
fit.line |
if TRUE (default) adds fit line with SE |
ci |
passes confidence interval width for fit curve (defaults to 0.95) |
npoints |
number of data points to for fit line. Either specify a number, or "same" will return a simulation of the same size as the original dataset. |
orig_jitter |
amount of jitter to apply to original dataset (default 0.10) |
sim_jitter |
amount of jitter to apply to simulated data (default 0.10) |
ggplot object with simulated data plotted with original
## Anwar M, Green JA, Norris P, et al ## Prospective daily diary study reporting of any and all symptoms in healthy ## adults in Pakistan: prevalence and #' response ## BMJ Open 2017;7:e014998 data(symptom) glm.symptom <- glm(actual_help_days ~ symp_days_reported, family = "poisson", data = symptom) sim.plot(glm.symptom)
## Anwar M, Green JA, Norris P, et al ## Prospective daily diary study reporting of any and all symptoms in healthy ## adults in Pakistan: prevalence and #' response ## BMJ Open 2017;7:e014998 data(symptom) glm.symptom <- glm(actual_help_days ~ symp_days_reported, family = "poisson", data = symptom) sim.plot(glm.symptom)
A dataset containing the age, gender, number of days on which symptoms were experienced, number of days on which help was sought, as well as measures of impulsivity and attitudes to medicines.
symptom
symptom
A data frame with 53940 rows and 10 variables:
participant ID, integer
age in 5 year bins, (18,20) (20,25) (25,30) (30,35) (35,40) (40,45) (45,50) (50,55) (55,60) (60,65)
female, male, character
Pakistan adaption of Beliefs about Medicines Questionnaire (Specific) Stored as POMP score 0-100
Pakistan adaption of Beliefs about Medicines Questionnaire (Necessity) Stored as POMP score 0-100
Pakistan adaption of Beliefs about Medicines Questionnaire, (Concern) Stored as POMP score 0-100
Pakistan adaption of Beliefs about Medicines Questionnaire, (General) Stored as POMP score 0-100
Pakistan adaption of Barratt Impuslivity Scale, Stored as POMP score 0-100
Number of days on which symptoms were reported, Non-negative integer (days)
Number of days on which participants visited some type of health professional, Non-negative integer
data from Anwar M, Green JA, Norris P, et al Prospective daily diary study reporting of any and all symptoms in healthy adults in Pakistan: prevalence and #' response BMJ Open 2017;7:e014998 doi:10.1136/bmjopen-2016-014998