{ #function to calulate the CDF of a vector.. #Estimate the CDF at N points on a grid #Suppose 'x' is the vector containing the data #Example create data from Normal distribution.. x = rnorm(500) #create a bunch of points to estimate the CDF N=250 xx1=seq(min(x),max(x),length=N) xx=c(-999,xx1) source("qgaus.r") #source the function you wish to use for integration # Normal, Gamma, Lognormal etc.. source("integrand-normal.r") #source("integrand-gamma.r") # CDF at the created points 'xxl' using numerical integration zz=1:N N1=N+1 for(i in 2:N1){ x1=xx[i-1] x2=xx[i] zz[i-1]=qgaus(x1,x2,x)} zz=cumsum(zz) # CDF at the points 'xxl' using the CDF command - i.e., 'pnorm' zz1=pnorm(xx1,mean(x),sd(x)) # Plot the CDf from the numerical integratrion.. plot(xxl, zz, xlab="X', ylab="CDF, F(x)", type="l", col="red") #overlay CDF from the 'pnorm' command lines(xxl, zzl, col="blue") #if we want to estimate the CDF at the data points #xs=sort(x) #N=length(x) #zz=1:N #for(i in 1:N){ #zz[i]=qgaus(-999,xs[i],x)} #zz1=pnorm(xs,mean(x),sd(x)) #get a quantile.. #xp=runif(1,0,1) #zzx=c(xp,zz) #zord=rank(zzx) #qp=xs[zord[1]] #qnorm(xp,mean(x),sd(x)) }