Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot estimated CDF with empirical CDF

Tags:

r

ecdf

I am fitting a distribution to a given data.then I have estimated parameters of the distribution.I have also plotted the empirical cdf using ecdf() command in R. Now I have to plot cdf of estimated distribution along with empirical cdf. How I can do it? Can the ecdf() command still help me?

like image 873
user2881894 Avatar asked Feb 02 '26 05:02

user2881894


1 Answers

Yes, ecdfcan help you. It has a plotting method. Below you see possible code for a normal distribution.

x <- rnorm(100)
plot(ecdf(x))
lines(seq(-3, 3, by=.1), pnorm(seq(-3, 3, by=.1)), col=2)

EDIT: You can do the same thing using the log-logistic distribution function instead. It is implemented for instance in package actuar.

# load package
require(actuar)
# check out the parametrization! 
?dllogis
# estimate shape and scale from your data
shape <- 20
scale <- 1
# Don't do this. Use your own data instead. 
x <- rllogis(100, shape=shape, scale=scale)
# Plotting the empirical distribution function
plot(ecdf(x))
# x-values for plotting distribution function
xvals <- seq(min(x), max(x), length=100)
# plot estimated distribution function with your estimated shape and scale
lines(xvals, pllogis(xvals, shape=shape, scale=scale), col=2)
like image 183
shadow Avatar answered Feb 04 '26 20:02

shadow