rpl_optim: Wrapper for the 'optim' function (includes Fisher...

View source: R/functions.R

rpl_optimR Documentation

Wrapper for the 'optim' function (includes Fisher transformation)

Description

Wrapper for the 'optim' function (includes Fisher transformation)

Usage

rpl_optim(
  param_init,
  mydata,
  pi,
  offsets = NULL,
  block_indices = NULL,
  seed = 12345,
  count_pairs = FALSE,
  parallel = FALSE,
  BPPARAM = NULL,
  method = "L-BFGS-B"
)

Arguments

param_init

Vector providing initial values for all parameters (means followed by correlations)

mydata

Data matrix

pi

Bernoulli sampling parameter (0 < pi <= 1)

offsets

If needed, a matrix of offsets (optional)

block_indices

List of vectors providing indices for each block for blockwise exchangeable correlation matrices

seed

Seed to use for random number generation

count_pairs

If TRUE, return the number of observations retained for each pair of variables used in the randomized pairwise likelihood

parallel

If TRUE, some computations are parallelized with the BiocParallel package

BPPARAM

If parallel=TRUE, the registry of back-ends for use in parallelized calculations

method

Optimization method to be used (see ?optim for more information)

Value

Optimized values for all parameters using the randomzed pairwise likelihood.

References

Mazo, G., Karlis, D., Rau, A. (2021) A randomized pairwise likelihood method for complex statistical inferences. In revision. hal-03126621.

Examples


## 1) Simulate exchangeable correlation matrix ---------------------------------
d <- 10
sim_exchangeable <-
    simulate_mvt_poisson(n = 1000, d = d,
                         param = list(margins = rep(1, d), disp = 0.5),
                         type = "exchangeable")

init_exchangeable <- init(sim_exchangeable$data, type = "exchangeable")
run_exchangeable <- rpl_optim(init_exchangeable, sim_exchangeable$data, pi = 0.1)

## 2) Simulate unstructured correlation matrix ---------------------------------
d <- 4
sim_unstructured <-
    simulate_mvt_poisson(n = 1000, d = d,
                         param = list(margins = rep(1, d),
                                      disp = c(0.4,0.5,0.6,0.7,0.8,0.9)),
                         type = "unstructured")

init_unstructured <- init(sim_unstructured$data, type = "unstructured")
run_unstructured <- rpl_optim(init_unstructured, sim_unstructured$data, pi = 0.1)

## Calculate SE of estimated parameters
se_unstructured <- rpl_se(mydata=sim_unstructured$data,
                          parameters=run_unstructured$par,
                          pi = 0.1,
                          offsets=NULL, verbose=FALSE)


## 3) Simulate one-factor correlation matrix -----------------------------------
d <- 4
sim_factor <-
    simulate_mvt_poisson(n = 1000, d = d,
                         param = list(margins = rep(1, d),
                                      disp = seq(0, 1, length = d)),
                         type = "factor")

init_factor <- init(sim_factor$data, type = "factor")
run_factor <- rpl_optim(init_factor, sim_factor$data, pi = 0.1)

## Calculate SE of estimated parameters
se_factor <- rpl_se(mydata=sim_factor$data,
                          parameters=run_factor$par,
                          pi = 0.1,
                          offsets=NULL, verbose=FALSE)

## 4) Simulate block-exchangeable correlation matrix ---------------------------
d <- 10
block_indices <- list(c(1:5), c(6:10))
sim_block <-
    simulate_mvt_poisson(n = 1000, d = d,
                         block_indices = block_indices,
                         param = list(margins = rep(1, d),
                                      disp = c(0.5,0.1,0.8)),
                         type = "block_exchangeable")

init_block<- init(sim_block$data, type = "block_exchangeable",
                  block_indices = block_indices)
run_block <- rpl_optim(init_block, sim_block$data, pi = 0.1,
                       block_indices = block_indices)

andreamrau/rpl documentation built on April 26, 2023, 3:57 p.m.