[R] bootstrap

Bert Gunter gunter.berton at gene.com
Wed May 29 16:02:30 CEST 2013


library(boot) is wholly unnecessary.

Hint:

1000 * 5 = 5000

?sample

-- Bert

On Wed, May 29, 2013 at 6:15 AM, arun <smartpink111 at yahoo.com> wrote:
> Hi,
> You might need to check library(boot).  I have never used that before.  So, I can't comment much.  It is better to post on R-help list.  I had seen your postings on Nabble in the past.  Unfortunately those postings were not accepted in R-help.  You have to directly post at   r-help at r-project.org after registering at:
> https://stat.ethz.ch/mailman/listinfo/r-help
>
>
>
>
>
>
> ________________________________
> From: Angela Fel Padecio <solewolf301 at yahoo.com>
> To: arun <smartpink111 at yahoo.com>
> Sent: Wednesday, May 29, 2013 9:05 AM
> Subject: bootstrap
>
>
>
> hi. i have these dataset:
>
> set.seed(12345)
> S=1000
> generate <- function(size) {
> x1 <- rnorm(size, mean=0, sd=1)
> x2 <- rnorm(size, mean=0, sd=1)
> x3 <- rnorm(size, mean=0, sd=1)
> x4 <- rnorm(size, mean=0, sd=1)
> x5 <- rnorm(size, mean=0, sd=1)
> x6 <- rnorm(size, mean=0, sd=1)
> x7 <- rnorm(size, mean=0, sd=1)
> x8 <- rnorm(size, mean=0, sd=1)
> x9 <- rnorm(size, mean=0, sd=1)
> x10 <- rnorm(size, mean=0, sd=1)
> e<-rnorm(size, mean=0, sd=1)
> t_trueps <- (1 + exp( -(b0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6 + b7*x7
> + b2*x2*x2 + b4*x4*x4 + b7*x7*x7 + b1*0.5*x1*x3 + b2*0.7*x2*x4 +b3*0.5*x3*x5
> + b4*0.7*x4*x6 + b5*0.5*x5*x7 + b1*0.5*x1*x6 + b2*0.7*x2*x3 + b3*0.5*x3*x4
> + b4*0.5*x4*x5 + b5*0.5*x5*x6) ) )^-1
> prob.exposure <- runif(size)
> t <- ifelse(t_trueps > prob.exposure, 1, 0)
> y <- a0 + a1*x1 + a2*x2 + a3*x3 + a4*x4 +a5*x8 + a6*x9 + a7*x10 + g1*t + e
> sim <- as.data.frame(cbind(x1, x2, x3 ,x4, x5, x6, x7, x8, x9, x10, t, y))
> return(sim)
> }
> b0 <- 0.05
> b1 <- 0.95
> b2 <- -0.25
> b3 <- 0.6
> b4 <- -0.4
> b5 <- -0.8
> b6 <- -0.5
> b7 <- 0.7
> a0 <- -3.85
> a1 <- 0.3
> a2 <- -0.36
> a3 <- -0.73
> a4 <- -0.2
> a5 <- 0.71
> a6 <- -0.19
> a7 <- 0.26
> g1 <- -0.4
>
> How can i have a bootstrap sample of 5 from size 10 with 1000 replications, i.e,
>
> data<-generate(10)
>
> where entire row is chosen. for example, if i have this result:
>
>> data<-generate(10)
>> data
>            x1          x2         x3          x4         x5         x6
> 1   0.9374775 -2.26118020 -1.7502526 -0.04386488  0.6760577  0.5125265
> 2  -1.3379878  0.54495810 -1.1884175 -0.25142873 -0.7389659 -2.7850113
> 3  -0.5633375 -0.59191774 -1.4772120  0.74107022 -0.2862497  0.8067138
> 4   0.3050390 -0.40174654  0.2980965  0.19234445  1.0762513  0.1604186
> 5   0.6919353 -0.13762332 -0.5352159  0.69566392  1.3655018 -0.8463535
> 6   0.2988476  1.15431908 -0.1172911  1.38397105  0.2631057  1.7943873
> 7  -0.1424191 -0.06971174 -1.2759867 -1.25774074  1.2320712  1.7419884
> 8   1.1835778 -0.06363542 -0.4772019 -0.46848004  1.0064428 -0.6327513
> 9   0.1942304 -0.79500297 -1.1120049  0.60023523  0.2210129 -1.7187271
> 10 -2.3568380  0.34227984 -1.0006803 -0.09190608  0.1187722 -0.5756797
>            x7                  x8                x9                 x10           t         y
> 1   0.7249311  0.2420102  2.51106406  1.6699921 0 -2.019059
> 2  -0.5209441  0.4935232 -0.31236000 -0.7717535 1 -2.286814
> 3  -1.0086591  0.6120889 -0.19684965  0.3355901 0 -2.785737
> 4  -0.4003396  0.9890145 -2.10427706  0.5364553 1 -2.782166
> 5  -0.1662400 -0.1357740  0.80220396 -0.3509522 0 -2.424431
> 6   2.1162941  1.4961478  0.02505993  0.8154658 1 -6.140725
> 7   0.9965705  1.0531386  0.53474097 -0.1415918 0 -2.922637
> 8  -0.1959067 -0.3507144  1.15341204  0.6018451 1 -2.602453
> 9   1.0153402 -0.2612589 -0.70037063  0.4304613 1 -2.788079
> 10  0.5378466  0.8504346  1.66384979 -1.2695204 0 -3.749164
>
> entire entries of row 1,3,5,7,9 for instance are chosen with 1000. your help is highly appreciated.
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list