[R] by function ??

L.A. romsa at millect.com
Mon Dec 21 19:01:47 CET 2009



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.




More information about the R-help mailing list