[R] Confidence interval

Peter Ehlers ehlers at ucalgary.ca
Mon Feb 14 16:47:47 CET 2011


On 2011-02-13 18:31, Joshua Wiley wrote:
> Hi,
>
> The logical operators are actually vectorized, so I do not think you
> need a loop.  Does this do what you want?
>
> ## Some data
> set.seed(10)
> dat<- matrix(rnorm(500, sd = 3), nrow = 80)
>
> ## Hypothetical confidence interval
> ci<- c(-5, 5)
>
> ## Find the number of points outside interval
> sum(dat<  ci[1] | dat>  ci[2], na.rm = TRUE)
>
> Cheers,
>
> Josh

Or you could use (no simpler) findInterval():

  fI <- findInterval(dat, sort(ci))

## to see what's produced:
  table(fI)
#  0   1   2
# 28 512  20

## the 1s indicate values inside ci, etc,
## so we want

  sum(fI != 1)
# [1] 48

Peter Ehlers

>
> On Sun, Feb 13, 2011 at 4:26 PM, Syd88<jhea2850 at uni.sydney.edu.au>  wrote:
>>
>> Hi,
>> I am trying to determine how many points fall ouside the confidence interval
>> range.
>>
>> This is the code I have so far but it does not work. Any help would be
>> appreciated.
>>
>> Count<- vector ()
>> for (i in 1: nrow (dataname)){
>> if (dataname[i]<l.ci.post[1]//
>> dataname[i]>u.ci.post[i]){
>> count[i] ->  1
>> }else
>> {count[i] ->  0}
>> }
>>
>>
>>
>> symbol
>> // = or - not sure if this is the right symbol though
>> --
>> View this message in context: http://r.789695.n4.nabble.com/Confidence-interval-tp3304258p3304258.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>



More information about the R-help mailing list