[R] by function ??

L.A. romsa at millect.com
Wed Dec 23 01:49:31 CET 2009


Thanks, but that produces what I think is an estimated interval.
   I really want to use the above formula. I just can't figure out how to
get it to run by the LEAID.
It does require 9 observations to produce an interval, but I was showing a
sample.
Thanks again.
L.A.


Matthew Dowle-3 wrote:
> 
> Maybe this (with enough data for a CI) ? :
> 
>> Dataset = data.table(Dataset)
>> Dataset[,as.list(wilcox.test(ratio,conf.int=TRUE)$conf.int),by="LEAID"]
>      LEAID              V1      V2
> [1,]  6307   0.7200000   0.92
> [2,]  8300   0.5678462   0.83
> Warning messages:
> 1: In switch(alternative, two.sided = { :
>   Requested conf.level not achievable
> 
> 
> "L.A." <romsa at millect.com> wrote in message 
> news:1261418507079-976414.post at n4.nabble.com...
>>
>>
>> Well, I'm back again.
>>   Thanks for all the help. Besides working, it's helping me begin to
>> understand how these functions work.
>> I still have trouble reading or following the process of a function,
>> which
>> brings my next question:
>>
>> Dataset:
>>
>> LEAID     ratio
>> 3 6307     0.7200000
>> 1 6307     0.7623810
>> 2 6307     0.8600000
>> 4 6307     0.9200000
>> 5 8300     0.5678462
>> 7 8300     0.7700000
>> 6 8300     0.8300000
>>
>> Here I want to create confidence intervals around the median. My hang-up 
>> now
>> is how to do pbinom() by LEAID.
>>
>> Here's my script.
>>
>> Dataset$obs <- with(Dataset, ave(ratio, LEAID, FUN=function(x)length(x)))
>> obs <-by(Dataset[ , "ratio"], LEAID, length)
>> obsn <-by(Dataset[ , "obs"], LEAID, FUN=function(x)1:max(x))
>>
>> q <- obsn
>> n <- obs
>> pbinom <-pbinom(q, n, .5)
>> pbinom <- with(Dataset, by(obs, LEAID, FUN=function(x)pbinom(q, n, .5)))
>> x <- pbinom
>> x.nolag=x[2:n]
>> x.lag1=x[1:(obs-1)]
>> my.new=cbind(x.nolag,x.lag1)
>> x.fill= cbind(0,0)
>> my.dat.fr=rbind(x.fill, my.new)
>> my.dat.fr
>> pr=1 - (2 * my.dat.fr)
>> cil=ifelse(pr >= .95, Dataset[,"ratio"], 0)
>> cil
>> max=sort(cil)
>> LowerCI=round(max(max),digits=2)
>> LowerCI
>> cn=ifelse(pr >= .95, Dataset[,"ObsNumber"], 0)
>> cmax=sort(cn)
>> c=max(cmax)
>> prb=ifelse(pr >= .95, pr, 999)
>> con=sort(prb)
>> Confidence=min(con)
>> o= n -( c - 1)
>> ch=ifelse (q <= o , Dataset[,"Ratio"], 0)
>> UpperCI=round(max(ch),digits=2)
>> UpperCI
>>
>>
>> I hope your not growing tired of my questions, I try reading all I can 
>> find,
>> but I often can't seem understand it until I can actually see it in 
>> process.
>> Thanks,
>> L.A.
>> -- 
>> View this message in context: 
>> http://n4.nabble.com/by-function-tp955789p976414.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.
> 
> 

-- 
View this message in context: http://n4.nabble.com/by-function-tp955789p977494.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list