[R] Confidence interval from resampling

2011-06-23 Thread Adriana Bejarano
Dear R gurus,

I have the following code, but I still not know how to estimate and extract
confidence intervals (95%CI) from resampling.

Thanks!

~Adriana

#data
penta-c(770,729,640,486,450,410,400,340,306,283,278,260,253,242,240,229,201,198,190,186,180,170,168,151,150,148,147,125,117,110,107,104,85,83,80,74,70,66,54,46,45,43,40,38,10)
x-log(penta+1)
plot(ecdf(x), ylab=Probability, xlab=Concentration (Ln+1))

x.wei-fitdistr(x,weibull)
x.wei
 shapescale
  6.7291685   5.3769965
 (0.7807718) (0.1254696)
xwei.shape - x.wei$estimate[[1]]
xwei.scale -  x.wei$estimate[[2]]

x.wei-fitdistr(x,weibull)
x.wei
xwei.shape - x.wei$estimate[[1]]
xwei.scale -  x.wei$estimate[[2]]
curve(pweibull(x, shape=xwei.shape, scale = xwei.scale,lower.tail=TRUE,
log.p=FALSE), add=TRUE,col='green',lwd=3)

#draw random numbers from a weibull distribution 100 times with
shape=xwei.shape, scale = xwei.scale
draw - lapply(1:100, function(.x){
out-rweibull(x, shape=xwei.shape, scale = xwei.scale)
})
newx- data.frame(draw)

colnames(newx)-paste(x, 1:100, sep = )
newmat-data.matrix(newx)

# matrix of coefficients
rownum=2
colnum=100
ResultMat-matrix(NA, ncol=colnum, nrow=rownum)
rownum2=45
colnum2=100
ResultMat2-matrix(NA, ncol=colnum2, nrow=rownum2)

#loop through each column in the source matrix
for (i in 1:100)
{
sel_col-newmat[col(newmat)==i]
  {ResultMat[,i]-coef(fitdistr(sel_col,weibull))}
 xwei.shape- ResultMat[1,i]
   xwei.scale- ResultMat[2,i]
 curve(pweibull(x, shape=xwei.shape, scale=xwei.scale, lower.tail=TRUE,
log.p = FALSE), add=TRUE, col='grey',lwd=0.5)
 ResultMat2[,i]-pweibull(x, shape=xwei.shape, scale =
xwei.scale,lower.tail=TRUE, log.p=FALSE)
}

## convert dataframe to numeric
MatOut- as.matrix(ResultMat2)
mode(MatOut) - numeric

# initiate variables
mm-ml-mu-rep(0,length(MatOut[,1]))

# mean and upper/lower quantiles
for(i in 1:length(MatOut[,1])){
 mm[i]- mean(MatOut[i,])
 ml[i]- quantile(MatOut[i,], 0.025, na.rm=TRUE)
 mu[i]- quantile(MatOut[i,], 0.975, na.rm=TRUE)
}
#lines(x, mm, col=black)
lines(x, ml, col=blue, lwd=2)
lines(x, mu, col=blue, lwd=2)

[[alternative HTML version deleted]]

__
R-help@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.


[R] Help with bootstrapping regression

2009-06-29 Thread Adriana Bejarano
Dear R gurus,



I have the following x (conc)-y (rk) data.
rk-c(0.016,0.032,0.048,0.095,0.111,0.143,0.190,0.206,0.222,0.270,0.286,0.302,0.317,0.381,0.397,0.444,0.460,
0.476,0.492,0.508,0.524,0.540,0.556,0.651,0.698,0.714,0.810,0.825,0.841,0.921,0.937,0.952,0.968,0.984,1.000)

cc-c(0.4,0.53,1,1.595,1.643,1.8,2.667,3.315,3.6,3.9,3.908,4,4.429,5.8,6,7.826,8.54,8.66,9.298,9.601,10,10,11.056,
15.577,23.402,23.615,80,80,89,710,2950,6400,6400,6800,69755.766)

conc-log(cc+1)

Assuming a log-normal distribution, I would like to bootstrap only the
response variable (rk; say 100 times per x), plot simultaneously the
log-normal curves for each bootstrap replicate, estimate the 95% confidence
interval, and extract the central tendency and confidence intervals for a
specific rk (i.e., 0.15). I have attempted to follow the code by John Fox
with little success. Any help will be greatly appreciated!.

Adriana

[[alternative HTML version deleted]]

__
R-help@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.


[R] for loop help

2008-01-29 Thread Adriana Bejarano
Hi,



I have written the following code which works fine



step-5

numSim-15



N-double(numSim)

A-double(numSim)

F-double(numSim)

M-double(numSim)

genx-double(numSim)



for (i in 1:numSim) {



N[i]-20

PN-(runif(N[i], 0, 1))

A[i]-sum(ifelse(PN0.2, 1, 0))



PF- runif((A[i]*0.5), 0, 1)

F[i]-sum(ifelse(PF0.2, 1, 0))



PM- runif((A[i]*0.5), 0, 1)

M[i]-sum(ifelse(PM0.2, 1, 0))



genx[i]- (min(F[i], M[i])*12)



}



data-data.frame(N, A, F, M, genx)



What I would like to do next is to make 'genx' from step '1' the seed for N
in step '2'- run the above code 15 times (numSim), make 'genx' from step '2'
the seed for N in step '3'- run the above code 15 times (numSim) etcÂ…



How do I do that?. Any advice would be greatly appreciated



Adriana (R-beginner)

[[alternative HTML version deleted]]

__
R-help@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.