R: gof plot - CDF & ECDF

 avatar
user_6939821
r
4 months ago
949 B
2
Indexable
## You can use stat_function() to draw a line where the 
# function is evaluated for a sequence of positions along 
# the x-axis. You can use rlang-style lambda notation to 
# give the function as a formula, 
# wherein .x represents the x position fed to the function.

library(ggplot2)
## 

data1 <- c(12.20,23.56,23.74,25.87,31.98,37,41.35,47.38,55.46,
           58.36,63.47,68.46,78.26,74.47,81.43,84,92,94,
           110,112,119,127,130,133,140,146,155,
           159,173,179,194,195,209,249,281,319,
           339,432,469,519,633,725,817,1776)

df <- data.frame(data1)
alpha  <- 273.8
lambda <- 29.8
beta   <- 1.135


ggplot(df, aes(data1)) + 
  stat_ecdf(geom = "step", aes(colour = "ECDF")) + 
  stat_function(
    fun = ~ (alpha^exp(-lambda * .x^(-beta)) - 1)/(alpha - 1),
    aes(colour = "TCDF"), xlim = c(0, 1700)
  ) +
  theme_light() +
  labs(
    x = "Time",
    y = "Fn(x)",
    title = "Empirical Distribution Function"
  )
  
  
Editor is loading...
Leave a Comment