I've build density function and now I want to calculate the probability of a new data point to "fall" into selected interval (say, a=3, b=7). So, I'm looking for:
P(a<x<=b)
Some sample data:
df<- data.frame(x=c(sample(6:9, 50, replace=TRUE), sample(18:23, 25, replace=TRUE)))
dens<- density(df$x)
I'll be happy to hear of any solution, but preferably in base r
Thank you in advance
A distribution has a density function if and only if its cumulative distribution function F ( x) is absolutely continuous. In this case: F is almost everywhere differentiable, and its derivative can be used as probability density: d d x F ( x ) = f ( x ) . {\displaystyle {\frac {d} {dx}}F (x)=f (x).}
With Cuemath, find solutions in simple and easy steps. Find the probability density function for f (x) = x 2 + 2x for the interval [1, 3] and verify it using the probability density function calculator Find the probability density function for f (x) = 3x 2 - 4x for the interval [2, 4] and verify it using the probability density function calculator
The following are the applications of the probability density function: 1 The probability density function is used in modelling the annual data of atmospheric NOx temporal concentration 2 It is used to model the diesel engine combustion 3 In Statistics, it is used to calculate the probabilities associated with the random variables.
The probability density function is non-negative for all the possible values, i.e. f (x)≥ 0, for all x. Due to the property of continuous random variables, the density function curve is continued for all over the given range.
You need to get the density as a function (using approxfun
)and then integrate the function over the desired limits.
integrate(approxfun(dens), lower=3, upper=7)
0.258064 with absolute error < 3.7e-05
## Consistency check
integrate(approxfun(dens), lower=0, upper=30)
0.9996092 with absolute error < 1.8e-05
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With