Type: | Package |
Title: | Test Model Fit with Simulation |
Version: | 0.1.0 |
Maintainer: | James Green <James.Green@ul.ie> |
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. |
Imports: | magrittr |
Depends: | R (≥ 2.10), ggplot2 |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.1.1 |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2021-05-14 17:07:51 UTC; limeg |
Author: | James Green |
Repository: | CRAN |
Date/Publication: | 2021-05-17 07:30:12 UTC |
Pipe operator
Description
See magrittr::%>%
for details.
Usage
lhs %>% rhs
Arguments
lhs |
A value or the magrittr placeholder. |
rhs |
A function call using the magrittr semantics. |
Value
The result of calling 'rhs(lhs)'.
Fit Simulated Data to a Model.
Description
Fit Simulated Data to a Model.
Usage
pred.fit(model, xpred = NULL, ci = 0.95, npoints = "same")
Arguments
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. |
Value
predicted data
Examples
## 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)
Description
Add model fit line (with SE) to GLM models (Poisson, negative binomial etc)
Usage
pred.plot(model, xpred = NULL, ci = 0.95)
Arguments
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) |
Value
ggplot object with fit line
Examples
#' ## 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
Description
Plot simulated data from a GLM model
Usage
sim.plot(
model,
xpred = NULL,
seed = NULL,
fit.line = TRUE,
ci = 0.95,
npoints = "same",
orig_jitter = 0.1,
sim_jitter = 0.1
)
Arguments
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) |
Value
ggplot object with simulated data plotted with original
Examples
## 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)
Responses to symptoms from a sample of the general population of Pakistan.
Description
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.
Usage
symptom
Format
A data frame with 53940 rows and 10 variables:
- id
participant ID, integer
- age5
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)
- gender
female, male, character
- bmq_spec
Pakistan adaption of Beliefs about Medicines Questionnaire (Specific) Stored as POMP score 0-100
- bmq_necess
Pakistan adaption of Beliefs about Medicines Questionnaire (Necessity) Stored as POMP score 0-100
- bmq_concern
Pakistan adaption of Beliefs about Medicines Questionnaire, (Concern) Stored as POMP score 0-100
- bmq_general
Pakistan adaption of Beliefs about Medicines Questionnaire, (General) Stored as POMP score 0-100
- bis
Pakistan adaption of Barratt Impuslivity Scale, Stored as POMP score 0-100
- symp_days_reported
Number of days on which symptoms were reported, Non-negative integer (days)
- actual_help_days
Number of days on which participants visited some type of health professional, Non-negative integer
Source
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