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
:
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)
$$ \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)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.