pbcm.di: Data-informed Parametric Bootstrap Cross-fitting

Description Usage Arguments Details Value Author(s) References Examples

View source: R/pbcm.di.R

Description

The data-informed Parametric Bootstrap Cross-fitting Method (PBCM) generates synthetic data from two models of a phenomenon parameterized by fits to an empirical dataset, and then cross-fits the models to these data. The result is two distributions of the goodness of fit metric Δ GoF = GoF_1 - GoF_2, where GoF_1 is the fit of model 1 and GoF_2 the fit of model 2.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
pbcm.di(
  data,
  fun1,
  fun2,
  genfun1,
  genfun2,
  reps,
  args1 = NULL,
  args2 = NULL,
  genargs1 = NULL,
  genargs2 = NULL,
  print_genargs = TRUE,
  nonparametric_bootstrap = TRUE,
  verbose = TRUE,
  GoFname = "GoF"
)

Arguments

data

Data frame

fun1

First modelling function

fun2

Second modelling function

genfun1

Generator function for first model

genfun2

Generator function for second model

reps

Number of Monte Carlo repetitions

args1

List of arguments passed to fun1

args2

List of arguments passed to fun2

genargs1

List of arguments passed to genfun1

genargs2

List of arguments passed to genfun2

print_genargs

Whether the generator argument values should be included in output (see Details)

nonparametric_bootstrap

Whether data should be nonparametrically bootstrapped before the parametric bootstrap

verbose

If TRUE, a progress bar is printed to the console and warnings are issued

GoFname

Name of the element returned by fun1 and fun2 holding the goodness of fit; see Details

Details

Functions fun1 and fun2 must take data as an argument in addition to any arguments specified in args1 and args2. Moreover, these functions must return a list with at least one element carrying the goodness of fit; the name of this element may be specified through the GoFname argument, by default the string "GoF" is assumed. Functions genfun1 and genfun2 must take an argument named model (the output of fun1 and fun2).

Value

A data frame in long format with the following columns:

rep

Monte Carlo repetition number

generator

Generating model

GoF1

Goodness of fit of model 1

GoF2

Goodness of fit of model 2

DeltaGoF

Equals GoF1 - GoF2

In addition to these columns, if print_genargs == TRUE, each argument in the lists genargs1 and genargs2 is included as a column of its own, with the argument's name prefixed by "genargs1_" or "genargs2_".

Author(s)

Henri Kauhanen

References

Wagenmakers, E.-J., Ratcliff, R., Gomez, P. & Iverson, G. J. (2004) Assessing model mimicry using the parametric bootstrap. Journal of Mathematical Psychology, 48(1), 28–50. https://doi.org/10.1016/j.jmp.2003.11.004

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
x <- seq(from=0, to=1, length.out=100)
mockdata <- data.frame(x=x, y=x + rnorm(100, 0, 0.5))

myfitfun <- function(data, p) {
  res <- nls(y~a*x^p, data, start=list(a=1.1))
  list(a=coef(res), GoF=deviance(res))
}

mygenfun <- function(model, p) { 
  x <- seq(from=0, to=1, length.out=100)
  y <- model$a*x^p + rnorm(100, 0, 0.5)
  data.frame(x=x, y=y)
}

pbcm.di(data=mockdata, fun1=myfitfun, fun2=myfitfun, genfun1=mygenfun,
        genfun2=mygenfun, reps=20, args1=list(p=1), args2=list(p=2), 
        genargs1=list(p=1), genargs2=list(p=2))

hkauhanen/pbcm documentation built on July 6, 2020, 12:25 a.m.