Learn R Programming

tidyvpc (version 1.1.0)

binless: binless

Description

Perform binless Visual Predictive Check (VPC)

Usage

binless(o, ...)

# S3 method for tidyvpcobj binless( o, qpred = c(0.05, 0.5, 0.95), optimize = TRUE, optimization.interval = c(0, 7), conf.level = 0.95, loess.ypc = FALSE, lambda = NULL, span = NULL, ... )

Arguments

o

tidyvpc object

...

other arguments

qpred

numeric vector of length 3 specifying quantiles (lower, median, upper) i.e. c(0.1, 0.5, 0.9)

optimize

logical indicating whether lambda and span should be optimized using AIC

optimization.interval

numeric vector of length 2 specifying interval for lambda optimization

conf.level

numeric confidence level for binless fit

loess.ypc

logical indicating loess precition corrected. Must first use predcorrect() if loess.ypc = TRUE

lambda

numeric vector of length 3 specifying lambda values for each quantile

span

numeric number between 0,1 specying smoothing paramter for loess prediction corrected

Value

Updates tidyvpcobj with additive quantile regression fits for observed and simulated data for quantiles specified in qpred argument. If optimize = TRUE argument is specified, the resulting tidyvpcobj will contain optimized lambda values according to AIC. For prediction corrected VPC (pcVPC), specifying loess.ypc = TRUE will return optimized span value for LOESS smoothing.

Details

Use this function in subsitute of traditional binning methods to derive VPC using additive quantile regression and loess for pcVPC.

See Also

observed simulated censoring predcorrect stratify binning vpcstats

Examples

Run this code
# NOT RUN {
obs_data <- data.table::as.data.table(tidyvpc::obs_data)
sim_data <- data.table::as.data.table(tidyvpc::sim_data)

obs_data <- obs_data[MDV == 0]
sim_data <- sim_data[MDV == 0]


 vpc <- observed(obs_data, y = DV, x = TIME) %>%
      simulated(sim_data, y = DV) %>%
      binless() %>%
      vpcstats()
      
 # Binless example with LOESS prediction correction
 
 obs_data$PRED <- sim_data[REP == 1, PRED]
 
 vpc <- observed(obs_data, y = DV, x = TIME) %>%
      simulated(sim_data, y = DV) %>%
      predcorrect(pred = PRED) %>%
      binless(optimize = TRUE, loess.ypc = TRUE) %>%
      vpcstats()
      
# Binless example with user specified lambda values stratified on 
# "GENDER" with 2 levels ("M", "F"), 10%, 50%, 90% quantiles.
 
 lambda_strat <- data.table(
 GENDER_M = c(3,5,2),
 GENDER_F = c(1,3,4)
 )
 
 vpc <- observed(obs_data, y = DV, x = TIME) %>%
      simulated(sim_data, y = DV) %>%
      stratify(~ GENDER) %>%
      binless(qpred = c(0.1, 0.5, 0.9), optimize = FALSE, lambda = lambda_strat) %>%
      vpcstats()
# }

Run the code above in your browser using DataLab