pbcm.du: Data-uninformed Parametric Bootstrap Cross-fitting

Description Usage Arguments Details Value Author(s) References Examples

View source: R/pbcm.du.R

Description

The data-uninformed Parametric Bootstrap Cross-fitting Method (PBCM) generates synthetic data from two models of a phenomenon with given model parameter values, 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
pbcm.du(
  fun1,
  fun2,
  genfun1,
  genfun2,
  reps,
  args1 = NULL,
  args2 = NULL,
  genargs1 = NULL,
  genargs2 = NULL,
  print_genargs = TRUE,
  verbose = TRUE,
  GoFname = "GoF"
)

Arguments

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)

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 an argument named data in addition to any arguments specified in args1 and args2; this is used to pass the synthetic data generated by genfun1 and genfun2. 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.

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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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(a, p) { 
  x <- seq(from=0, to=1, length.out=100)
  y <- a*x^p + rnorm(100, 0, 0.5)
  data.frame(x=x, y=y)
}

pbcm.du(fun1=myfitfun, fun2=myfitfun, genfun1=mygenfun, genfun2=mygenfun, 
        reps=20, args1=list(p=1), args2=list(p=2), 
        genargs1=list(a=1.1, p=1), genargs2=list(a=1.1, p=2))

sweep <- lapply(X=seq(from=0.5, to=1.5, by=0.1),
                FUN=function(X) {
                  pbcm.du(fun1=myfitfun, fun2=myfitfun, genfun1=mygenfun,
                          genfun2=mygenfun, reps=20,
                          args1=list(p=1), args2=list(p=2), 
                          genargs1=list(a=X, p=1), genargs2=list(a=X, p=2))
                })

sweep <- do.call(rbind, sweep)

sweep$parameter <- ifelse(is.na(sweep$genargs1_a), sweep$genargs2_a, sweep$genargs1_a)

## Not run: 
  library(ggplot2)
  g <- ggplot(sweep, aes(x=DeltaGoF, fill=generator)) + geom_density(alpha=0.5) 
  g <- g + facet_wrap(.~parameter)
  print(g)

## End(Not run)

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