CPSS_fit: Applies a fit function repeatedly to subsamples drawn as...

Description Usage Arguments Details Value Examples

View source: R/stability_function.R

Description

Applies a fit function repeatedly to subsamples drawn as complementary pairs (CPSS).

Usage

1
CPSS_fit(n, fitting_func, B = 50, parallel = TRUE, num_cores = NULL)

Arguments

n

An integer >= 2, the sample size.

fitting_func

A function that takes a vector of indices (a subvector of 1:n) and returns some value that supports the "+" operation (e.g. an estimated adjacency matrix).

B

An integer, number of pairs of subsamples to be drawn. Defaults to 50.

parallel

A logical that indicates whether parallel::mclapply() should be used for fitting. Otherwise, lapply() is used.

num_cores

An integer, number of cores to be used if parallel; will be set to parallel::detectCores() - 1 if NULL. Defaults to NULL.

Details

A complementary pair of sub-indices of 1:n is a pair of disjoint subvectors 1:n each with length floor(n/2). The function draws B such pairs, and apply fitting_func() to each of these 2*B lists of sub-indices. Finally, the sum of the 2*B returned values/vectors/matrices from fitting_func() are returned. Assuming fitting_func takes a list of indices and returns an adjacency matrix, each entry in CPSS_fit(n, fitting_func, B) returns the number of times that entry equals to 1 in the 2*B estimated adjacency matrices.

Note: The user is expected to call CPSS_fit(), followed by CPSS_path(), and then followed by CPSS_control().

Value

The sum of results from fitting_func() applied to 2*B lists of sub-indices of 1:n.

Examples

1
2
3
4
5
6
7
m <- 3; n <- 200; B <- 5
adj_mat <- ZiDAG::make_dag(m, mode = "chain")
d <- ZiDAG::gen_zero_dat(seed=1, gen_para="pms", adj_mat=adj_mat, n=n, gen_uniform_degree=1)
fitting_func <- function(indices) return (
    ZiDAG::ziGDS(V=d$V[indices,], Y=d$Y[indices,], parametrization="pms", verbose=FALSE,
    control=list("max_uniform_degree"=1L, "tol"=1e-8, "print_best_degree"=FALSE)))
freq_B <- ZiDAG::CPSS_fit(nrow(d$V), fitting_func, B=B, parallel=TRUE, num_cores=1)

sqyu/ZiDAG documentation built on Jan. 19, 2021, 4:11 p.m.