2

I have a random variable which I can obtain the density of

density(r)->pdf

how can I obtain the cumulative distribution function (cdf) from this pdf with R?

I tried

approxfun(pdf$x,pdf$y,yleft=0,yright=0)->f
cdf<-integrate(f,-Inf,2)

but when I plot cdf I only obtain

1.000396 with absolute error < 7.9e-05

Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
triub
  • 95
  • 1
  • 4

1 Answers1

1

You can use the logspline package of R for creating and visualising smooth nonparametric cumulative distribution functions (and other related quantities) as follows.

library(logspline) # load the package
x <- rnorm(500) # generate some data
x.lsp <- logspline(x) # create the logspline object
plot(x.lsp, what="p") # plot the distribution function
plot(x.lsp, what="d") # plot the density function
utobi
  • 279
  • 8
  • 16