Estimation with `maxlogL` objects"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

These are basic examples which shows you how to solve a common maximum likelihood estimation problem with EstimationTools:

Estimation in regression models

We generate data from an hypothetical failure test of approximately 641 hours with 40 experimental units, 20 from group 1 and 20 from group 2. Lets assume a censorship rate of 10%, and regard that the data is right censored. Six of the 20 data points are shown just bellow:

if (!require('readr')) install.packages('readr')
library(readr)

urlRemote <- "https://raw.githubusercontent.com/"
pathGithub <- 'Jaimemosg/EstimationTools/master/extra/'
filename <- 'sim_wei.csv'
myURL <- paste0(urlRemote, pathGithub, filename)
data_sim <- read_csv(myURL)

data_sim$group <- as.factor(data_sim$group)
head(data_sim)

The model is as follows:

$$ f(t|\alpha, k) = \frac{\alpha}{k} \left(\frac{t}{k}\right)^{\alpha-1} \exp\left[-\left(\frac{t}{k}\right)^{\alpha}\right] $$

\centering $$ \begin{aligned} T &\stackrel{\text{iid.}}{\sim} WEI(\alpha,\: k), \ \log(\alpha) &= 1.2 + 0.1 \times group \quad (\verb|shape|),\ k &= 500 \quad (\verb|scale|). \end{aligned} $$

The implementation and its solution is printed below:

library(EstimationTools)

# Formulas with linear predictors
formulas <- list(scale.fo = ~ 1, shape.fo = ~ group)

# The model
fit_wei <- maxlogLreg(formulas, data = data_sim,
                      y_dist = Surv(Time, status) ~ dweibull,
                      link = list(over = c("shape", "scale"),
                                  fun = rep("log_link", 2)))
summary(fit_wei)

Estimation in distributions

$$ \begin{aligned} X &\sim N(\mu, \:\sigma^2), \ \mu &= 160 \quad (\verb|mean|), \ \sigma &= 6 \quad (\verb|sd|). \end{aligned} $$

The solution for a data set generated with size $n=10000$ is showed below

x <- rnorm( n = 10000, mean = 160, sd = 6 )
fit <- maxlogL( x = x, dist = "dnorm", link = list(over = "sd", fun = "log_link") )
summary(fit)


Try the EstimationTools package in your browser

Any scripts or data that you put into this service are public.

EstimationTools documentation built on Dec. 10, 2022, 9:07 a.m.