Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check interval contains number in R

In R I have the following matrix (each row represents a bootstrap 95% confidence interval generated from the same sample data):

       low   high
[1,]   22.2  25.5
[2,]   23.1  25.9
[3,]   23.4  26.1
...

I know the true population mean of the data, it's 23.3. So the first two include the true mean but the third does not.

In R, I want to run a for loop i through nrow(matrix) times, each i checking whether or not the true population mean of the data is in that particular interval, then return a column vector of height nrow(matrix) of TRUE if the interval contains the true mean, and FALSE otherwise.

How could I do this?

like image 546
dplanet Avatar asked Mar 24 '12 22:03

dplanet


1 Answers

You can simply use the inequality operators directly on the matrix columns. So I would have simply done:

> cbind( mat[,1] <= 23.3 & mat[,2] >= 23.3 )

      [,1]
[1,]  TRUE
[2,]  TRUE
[3,] FALSE
like image 185
Prasad Chalasani Avatar answered Oct 04 '22 12:10

Prasad Chalasani