Compare runtime using CGGibbs and naive approach to calculate linear predictor
Source:R/measure_performance.R
compare_eta_comptime_across_nvars.Rd
The comparison of the methods is described in
this vignette.
The user can specify different arguments to alter the specification of the comparison, but it's
possible to only specify values of the n_vars
argument. It's not possible to change the fact that
data is simulated with a normal response and normal explanatory variables.
Usage
compare_eta_comptime_across_nvars(
n_vars,
n = 100,
beta_prior = distributional::dist_normal(0, 1),
log_likelihood_extra_args = list(sd = 1),
sample_method = c("slice_sampling", "normal-normal"),
qslice_fun = qslice::slice_stepping_out,
...,
n_samples = 500,
burnin = 100,
parallelise = FALSE,
n_cores = as.numeric(Sys.getenv("NUMBER_OF_PROCESSORS")) - 1
)
Arguments
- n_vars
a
numeric vector
with numbers of normally distributed columns in the design matrix for different runs- n
a
numeric
with the number of observations in the data analysed by the GLM- beta_prior
a
distribution
object created by a function from thedistributional
package. Could fx. bedistributional::dist_normal(mean = 0, sd = 1)
.- log_likelihood_extra_args
a named
list
with arguments passed onto the log_density function. Fx. specification oflog_likelihood_extra_args = list(sd = x)
is needed for the case offamily = "gaussian"
- sample_method
a
character
specifying the method used for sampling. The default"slice_sampling"
is the intended value in most cases, as it works for any specification offamily
andbeta_prior
."normal-normal"
uses a conditional normal distribution to sample from in case of conjugate prior with gaussian response andbeta_prior
. Implemented for testing purposes but works for that niche case.- qslice_fun
a
function
from the qslice package. Default is qslice::slice_stepping_out which uses the slice sampler from Neal 2003, but all functions are available.- ...
arguments passed onto the function specified by
qslice_fun
. For default qslice::slice_stepping_outw
needs to be specified, while for fx. qslice::slice_elliptical,mu
andsigma
need to be specified- n_samples
a
numeric
with number of samples to draw of each parameter(/variable) in the model- burnin
a
numeric
with the number of samples to be marked as "burnin". Burnin samples are not included in thebeta_mean
calculation to increase finite sample performance of the LLN estimate- parallelise
a
logical
if the runs of the algorithm across values ofn_vars
should be parallelised using future.apply::future_lapply- n_cores
a
numeric
with the number of cores to use for parallelisation. Default is 1 less than the number of available cores
Examples
# Compare the runtime for 2, 20, 40, 60 variables in the model
compare_eta_comptime_across_nvars(n_vars = c(2, seq(from = 20, to = 60, by = 20)),
n_samples = 1,
burnin = 0)
#> time linear_predictor_calc n_vars n_samples beta_mean
#> 1 0.01716685 secs update 2 1 0
#> 2 0.02163410 secs naive 2 1 0
#> 3 0.46144390 secs update 20 1 0
#> 4 0.20999956 secs naive 20 1 0
#> 5 0.84110141 secs update 40 1 0
#> 6 1.39404273 secs naive 40 1 0
#> 7 1.70097470 secs update 60 1 0
#> 8 1.65817809 secs naive 60 1 0
#> beta_variance family sd qslice_fun w parallelised
#> 1 1 gaussian 1 qslice::slice_stepping_out 0.5 FALSE
#> 2 1 gaussian 1 qslice::slice_stepping_out 0.5 FALSE
#> 3 1 gaussian 1 qslice::slice_stepping_out 0.5 FALSE
#> 4 1 gaussian 1 qslice::slice_stepping_out 0.5 FALSE
#> 5 1 gaussian 1 qslice::slice_stepping_out 0.5 FALSE
#> 6 1 gaussian 1 qslice::slice_stepping_out 0.5 FALSE
#> 7 1 gaussian 1 qslice::slice_stepping_out 0.5 FALSE
#> 8 1 gaussian 1 qslice::slice_stepping_out 0.5 FALSE