The estimtf package provides functions to find the Maximum Likelihood estimates of parameters from parametric distributions and linear regression models using TensorFlow optimizers.
This document introduces you to estimtf set of tools, and shows you how to apply them to estimate these parameters.
devtools::install_github('SaraGarcesCespedes/estimtf', force=TRUE)
library(estimtf)This function is used to compute the Maximum Likelihood Estimators of distributional parameters using TensorFlow. Use ?mle_tf for more details.
# Estimation of both normal distribution parameters
x <- rnorm(n = 1000, mean = 10, sd = 3)
estimation1 <- mle_tf(x,
initparam = list(mean = 1.0, sd = 1.0),
xdist = "Normal",
optimizer = "AdamOptimizer",
hyperparameters = list(learning_rate = 0.1))
summary(estimation1)
# Estimation of parameter lambda from Instantaneous Failures distribution
pdf <- function(X, lambda) {
(1/((lambda^2)*(lambda-1)))*(lambda^2+X-2*lambda)*exp(-X/lambda)
}
x <- c(3.4,0.0,0.0,15.8,232.8,8.8,123.2,47,154,103.2,89.8, 12.2)
estimation2 <- mle_tf(x = x,
xdist = pdf,
initparam =list(lambda = rnorm(1, 2, 1)),
optimizer = "AdamOptimizer",
hyperparameters = list(learning_rate = 0.1),
maxiter = 10000)
summary(estimation2)This function is used to compute the Maximum Likelihood Estimators of regression parameters using TensorFlow. Use ?mlereg_tf for more details.
# Estimation of parameters of a Poisson regression model
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
data <- data.frame(treatment, outcome, counts)
formulas <- list(lambda.fo = ~ outcome + treatment)
estimation1 <- mlereg_tf(ydist = counts ~ Poisson,
formulas = formulas, data = data,
initparam = list(rate = 1.0),
optimizer = "AdamOptimizer",
link_function = list(lambda = "log"),
hyperparameters=list(learning_rate=0.1))
summary(estimation1)
# Estimation of parameters of a linear regression model with one fixed parameter
x <- runif(n = 1000, -3, 3)
y <- rnorm(n = 1000, mean = 5 - 2 * x, sd = 3)
data <- data.frame(y = y, x = x)
formulas <- list(mean.fo = ~ x)
initparam <- list(mean = list(Intercept = 1.0, x = 0.0))
estimation2 <- mlereg_tf(ydist = y ~ Normal,
formulas = formulas,
data = data,
fixparam = list(sd = 3),
initparam = initparam,
optimizer = "AdamOptimizer",
hyperparameters = list(learning_rate = 0.1))
summary(estimation2)