MoTBFs (version 1.2)

univMoTBF: Fitting MoTBFs

Description

Function for fitting univariate mixture of truncated basis functions. Least square optimization is used to minimize the quadratic error between the empirical cumulative distribution and the estimated one.

Usage

univMoTBF(
  data,
  POTENTIAL_TYPE,
  evalRange = NULL,
  nparam = NULL,
  maxParam = NULL
)

Arguments

data

A "numeric" data vector.

POTENTIAL_TYPE

A "character" string specifying the potential type, must be one of "MOP" or "MTE".

evalRange

A "numeric" vector with the range where defining the function. By default: it is NULL and the function is defined over the data range.

nparam

Number of parameters of the function. By default: it is NULL and the function fits the best MoTBF taking into account the Bayesian information criterion (BIC) to penalize the functions. It evaluates the two next functions, if the BIC value doesn't improve then the function with the last best BIC is returned.

maxParam

A "numeric" value which indicate the maximum number of coefficients in the function. By default it is NULL; if not, the output is the function which gets the best BIC with at most this number of parameters.

Value

An "motbf" function learned from data.

Examples

Run this code
# NOT RUN {
## 1. EXAMPLE
## Data
X <- rnorm(5000)

## Learning
f1 <- univMoTBF(X, POTENTIAL_TYPE = "MTE"); f1
f2 <- univMoTBF(X, POTENTIAL_TYPE = "MOP"); f2

## Plots
hist(X, prob = TRUE, main = "")
plot(f1, xlim = range(X), col = 1, add = TRUE)
plot(f2, xlim = range(X), col = 2, add = TRUE)

## Data test
Xtest <- rnorm(1000)
## Filtered data test
Xtest <- Xtest[Xtest>=min(X) && Xtest<=max(X)]

## Log-likelihood
sum(log(as.function(f1)(Xtest)))
sum(log(as.function(f2)(Xtest)))

## 2. EXAMPLE
## Data
X <- rchisq(5000, df = 5)

## Learning
f1 <- univMoTBF(X, POTENTIAL_TYPE = "MTE", nparam = 11); f1
f2 <- univMoTBF(X, POTENTIAL_TYPE = "MOP", maxParam = 10); f2

## Plots
hist(X, prob = TRUE, main = "")
plot(f1, xlim = range(X), col = 3, add = TRUE)
plot(f2, xlim = range(X), col = 4, add = TRUE)

## Data test
Xtest <- rchisq(1000, df = 5)
## Filtered data test
Xtest <- Xtest[Xtest>=min(X) && Xtest<=max(X)]

## Log-likelihood
sum(log(as.function(f1)(Xtest)))
sum(log(as.function(f2)(Xtest)))

# }

Run the code above in your browser using DataLab