Krantz
Krantz

Reputation: 1493

Perform mathematical operations with the area under the curve from package ‘BSDA’

I have the following code to calculate the area under the curve:

library("BSDA")
normarea(0, 9.9, 10.5, 1.3)

My objective is to perform mathematical operations with the value of the "area under the curve", which in this case is 0.3222.

Specifically, I would like to be able to do this:

p<-normarea(0, 9.9, 10.5, 1.3)
q<-p*100
q
32.22

The problem is when I implement that code I get this error:

Error in p * 100 : non-numeric argument to binary operator

My question is: how can I extract the numerical component from the output of normarea?

I would appreciate any ideas.

Upvotes: 0

Views: 46

Answers (1)

Maurits Evers
Maurits Evers

Reputation: 50718

normarea just plots the area under the curve for a certain interval; it does not return the area, see ?normarea.

However, executing normarea let's you see the source code of the function; the area is simply calculated using pnorm as

area <- pnorm(upper, m, sig) - pnorm(lower, m, sig)

So in your case, let's define a function to return the area

area_norm <- function(lower, upper, m, sig) {
    pnorm(upper, m, sig) - pnorm(lower, m, sig)
}

Then

area_norm(0, 9.9, 10.5 1.3);
#[1] 0.3222062

Upvotes: 1

Related Questions