fit: Fit a Function to Each Element of a List of Data

Description Usage Arguments Details Value Author(s) Examples

View source: R/fit.R

Description

Fits a function to each element of a list of data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
fit(
  Xstar,
  fitFUN,
  ...,
  par = FALSE,
  ncores = NULL,
  mc = TRUE,
  lb = FALSE,
  cl_eval = FALSE,
  cl_export = FALSE,
  cl_expr,
  cl_vars,
  rbind = TRUE
)

Arguments

Xstar

List. A list of length R with a data set of length n in each element of the list.

fitFUN

Function. Fit function to be applied to each element of Xstar.

...

Argument to pass to fitFUN.

par

Logical. If TRUE, use multiple cores. If FALSE, use lapply().

ncores

Integer. Number of cores to use if par = TRUE. If unspecified, defaults to detectCores() - 1.

mc

Logical. If TRUE, use parallel::mclapply(). If FALSE, use parallel::parLapply() or parallel::parLapplyLB(). Ignored if par = FALSE.

lb

Logical. If TRUE use parallel::parLapplyLB(). If FALSE, use parallel::parLapply(). Ignored if par = FALSE and mc = TRUE.

cl_eval

Logical. Execute parallel::clusterEvalQ() using cl_expr. Ignored if mc = TRUE.

cl_export

Logical. Execute parallel::clusterExport() using cl_vars. Ignored if mc = TRUE.

cl_expr

Expression. Expression passed to parallel::clusterEvalQ() Ignored if mc = TRUE.

cl_vars

Character vector. Names of objects to pass to parallel::clusterExport() Ignored if mc = TRUE.

rbind

NULL or logical. If rbind = NULL, returns the list produced. If TRUE, uses rbind() to bind the rows of the list produced. If FALSE, uses cbind() to bind the columns of the list produced. Test that each element of the output list has the appropriate dimensions for binding before using this option.

Details

The first argument of fitFUN should be data The output of fitFUN should be a vector.

Options for explicit parallelism are provided. See par and suceeding arguments.

Value

Returns a list of parameter estimates.

Author(s)

Ivan Jacob Agaloos Pesigan

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
xstar <- univ(n = 100, rFUN = rnorm, mean = 100, sd = sqrt(225), R = 100)
thetahatstar <- fit(Xstar = xstar, fitFUN = mean, rbind = TRUE)
mean(thetahatstar)
Xstar <- mvn(
  n = 100,
  Sigma = matrix(c(1, .5, .5, 1), nrow = 2),
  R = 100
)
foo <- function(X) {
  as.vector(cov(X))
}
thetahatstar <- fit(Xstar = Xstar, fitFUN = foo, rbind = TRUE)
thetahatstar <- thetahatstar[, 2]
mean(thetahatstar)

jeksterslabds/jeksterslabRdata documentation built on July 24, 2020, 5:49 a.m.