require(graphics)
set.seed(123)
silent_curr <- cylcop_get_option("silent")
cylcop_set_option(silent = TRUE)
n <- 100 #n (number of samples) is set small for performance.
x <- rweibull(n, shape = 10)
dens_non_param <- fit_steplength(x = x, parametric = FALSE)
weibull <- fit_steplength(x = x, parametric = "weibull")
gamma <- fit_steplength(x = x, parametric = "gamma")
chisq <- fit_steplength(x = x, parametric = "chi-squared", start = list(df = 1))
true_dens <- dweibull(seq(0, max(x), length.out = 200),
shape = 10
)
dens_weibull <- dweibull(seq(0, max(x),length.out = 200),
shape = weibull$coef$shape,
scale = weibull$coef$scale
)
dens_gamma <- dgamma(seq(0, max(x),length.out = 200),
shape = gamma$coef$shape,
rate = gamma$coef$rate
)
dens_chisq <- dchisq(seq(0, max(x),length.out = 200),
df = chisq$coef$df
)
plot(seq(0,max(x),length.out = 200), true_dens, type = "l")
lines(dens_non_param$x, dens_non_param$y, col = "red")
lines(seq(0,max(x),length.out = 200), dens_weibull, col = "green")
lines(seq(0,max(x),length.out = 200), dens_gamma, col = "blue")
lines(seq(0,max(x),length.out = 200), dens_chisq, col = "cyan")
cylcop_set_option(silent = silent_curr)
Run the code above in your browser using DataLab