Re: [R] Why does Bootstrap work for one of similar models but not for the other?

2010-08-19 Thread Bert Gunter
In future, when posting data in your message use dput() or
textConnection() so that helpeRs can more easily load them.

I was not able to replicate your results. Here's what I got:


Bootstrap Statistics :
   originalbiasstd. error
t1*  0.99975370  0.0044205644  0.04110232
t2* -0.06091574 -0.0078646847  0.05778133
t3*  0.27506204  0.0006121326  0.05296862
t4* -0.03040424  0.0002096330  0.02826951

> sessionInfo()
R version 2.11.0 (2010-04-22)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
 [1] datasets  splines   grid  tcltk stats graphics  grDevices
 [8] utils methods   base

other attached packages:
[1] boot_1.2-42 TinnR_1.0.3 R2HTML_1.59-1   Hmisc_3.7-0
[5] survival_2.35-8 svSocket_0.9-48 lattice_0.18-3  MASS_7.3-5


What does

getOption("digits")

give you just before you run each bootstrap?

Bert Gunter
Genentech nonclinical Statistics



On Thu, Aug 19, 2010 at 12:50 AM, Reiko Akiyama  wrote:
> Dear all,
>
> Could anyone help me figure out why bootstrap works for one of similar
> models but not for the other and how I can solve it?
>
> I am using R 2.11.1 in Windows and would like to get confidence intervals
> for my models A and B by bootstrapping. However, bootstrap gives expected
> output for the model A but not for B, which I found was puzzling because the
> structure of the models is similar as I describe below. I had another person
> running the models in another computer and the same thing happens so this
> does not seem to be computer-specific. I could not find a clue for a
> solution in the R archive or in the R book (at least to the extent I
> understood).
>
> Here are the properties of the models A and B and what happens when I run
> bootstrap.
>
> modelA: rA~stA1+ stA2+stA3
> model B: rB~stB1+stB2+stB3
> The variables for the models A and B are in the same dataset called ?data?.
> The sample size is 32 for both models and the value range and distribution
> of the variables in the two models are similar. (Variables from both models
> are at the end of this enquiry.)
>
> [bootstrap of the model A]
>>
>> A.fun<-function(data,indices)coefficients(lm(rA~stA1+
>> stA2+stA3,data=data[indices,]))
>> bootA<-boot(data,A.fun,1000);bootA
>
> ORDINARY NONPARAMETRIC BOOTSTRAP
> Call:
> boot(data = data, statistic = A.fun, R = 1000)
> Bootstrap Statistics :
>       original       bias    std. error
> t1*  1.00016501 -0.004350842  0.05309877
> t2*  0.02343475  0.008501989  0.07638795
> t3* -0.01602954 -0.004980400  0.07806805
> t4*  0.03601194 -0.005417404  0.08510128
>
> [bootstrap of the model B]
>>
>>
>> B.fun<-function(data,indices)coefficients(lm(rB~stB1+stB2+stB3),data=data[indices,])
>> bootB<-boot(data,B.fun,1000);bootB
>
> ORDINARY NONPARAMETRIC BOOTSTRAP
> Call:
> boot(data = data, statistic = B.fun, R = 1000)
> Bootstrap Statistics :
>       original  bias    std. error
> t1*  0.99975370       0           0
> t2* -0.06091574       0           0
> t3*  0.27506203       0           0
> t4* -0.03040424       0           0
>
> What am I missing here?
> I highly appreciate any comments and suggestions.
>
> Best Wishes,
> Reiko Akiyama
> Uppsala University
> Sweden
>
> [Variables from the model A]
>>
>> rA
>
>  [1] 0.7100881 1.0406464 1.1100229 0.6182664 0.7345739 1.0577865 0.6856024
>  [8] 0.5264447 1.5793340 1.1793993 0.6488737 1.0214076 1.3589618 1.0528893
> [15] 1.5242409 1.3761019 0.9427032 0.6794809 1.4752693 0.7737512 1.0120797
> [22] 0.8692458 1.2079660 1.0610513 0.8570029 0.9794319 1.0957395 0.8243552
> [29] 0.4162586 1.4079334 1.0692132 1.1059419
>>
>> stA1
>
>  [1] -0.9126354 -0.8331680 -1.0239203 -0.3721959 -0.5311308  0.7564474
>  [7] -1.1828933 -1.2146727 -0.8172593 -0.9921410 -0.5152602 -0.9285442
> [13] -0.4198840 -0.9444529 -0.4198840 -0.8331680  1.2810163  1.4081718
> [19]  1.7102091  2.3460247  1.3806653  1.3127957  1.2333282  1.4240806
> [25] -0.1337555 -0.1973142  0.2954372 -0.1337555 -0.4039753 -0.3880665
> [31]  0.2795666 -0.2291317
>>
>> stA2
>
>  [1] -0.2292617 -0.4917962 -0.6437899 -1.2241293 -0.3398026 -2.0946384
>  [7] -1.0721356 -1.2655821 -1.3484877 -1.8873744 -0.7543307 -0.9615948
> [13] -0.3674378  0.4483537  0.8761467 -0.8786892  0.5312593  1.1524988
> [19]  0.3234425 -0.4088906  0.5102565  1.1945044  1.7748438  0.6827002
> [25]  0.6418001  1.1801340  0.4207184  0.8076114  0.9181522  0.6827002
> [31]  0.9037819  0.9181522
>>
>> stA3
>
>  [1]  0.86459627 -0.23416149 -2.00372671  0.04161491  0.78881988 -2.50869565
>  [7] -0.02608696 -0.84161491 -0.95465839 -0.28012422  0.47080745  0.07577640
> [13]  0.84223602  0.24472050  2.83975155  0.43043478 -0.75652174 -0.92795031
> [19]  0.29192547 -0.78633540 -0.78385093 -0.51242236  0.59627329  0.19068323
> [25]  0.02919255  1.17018634 -0.19440994  0.68385093  1.08881988 -0.28385093
> [31] -0.71118012  1.065

[R] Why does Bootstrap work for one of similar models but not for the other?

2010-08-19 Thread Reiko Akiyama

Dear all,

Could anyone help me figure out why bootstrap works for one of similar  
models but not for the other and how I can solve it?


I am using R 2.11.1 in Windows and would like to get confidence  
intervals for my models A and B by bootstrapping. However, bootstrap  
gives expected output for the model A but not for B, which I found was  
puzzling because the structure of the models is similar as I describe  
below. I had another person running the models in another computer and  
the same thing happens so this does not seem to be computer-specific.  
I could not find a clue for a solution in the R archive or in the R  
book (at least to the extent I understood).


Here are the properties of the models A and B and what happens when I  
run bootstrap.


modelA: rA~stA1+ stA2+stA3
model B: rB~stB1+stB2+stB3
The variables for the models A and B are in the same dataset called  
?data?. The sample size is 32 for both models and the value range and  
distribution of the variables in the two models are similar.  
(Variables from both models are at the end of this enquiry.)


[bootstrap of the model A]
A.fun<-function(data,indices)coefficients(lm(rA~stA1+  
stA2+stA3,data=data[indices,]))

bootA<-boot(data,A.fun,1000);bootA

ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = data, statistic = A.fun, R = 1000)
Bootstrap Statistics :
   original   biasstd. error
t1*  1.00016501 -0.004350842  0.05309877
t2*  0.02343475  0.008501989  0.07638795
t3* -0.01602954 -0.004980400  0.07806805
t4*  0.03601194 -0.005417404  0.08510128

[bootstrap of the model B]

B.fun<-function(data,indices)coefficients(lm(rB~stB1+stB2+stB3),data=data[indices,])
bootB<-boot(data,B.fun,1000);bootB

ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = data, statistic = B.fun, R = 1000)
Bootstrap Statistics :
   original  biasstd. error
t1*  0.99975370   0   0
t2* -0.06091574   0   0
t3*  0.27506203   0   0
t4* -0.03040424   0   0

What am I missing here?
I highly appreciate any comments and suggestions.

Best Wishes,
Reiko Akiyama
Uppsala University
Sweden

[Variables from the model A]

rA

 [1] 0.7100881 1.0406464 1.1100229 0.6182664 0.7345739 1.0577865 0.6856024
 [8] 0.5264447 1.5793340 1.1793993 0.6488737 1.0214076 1.3589618 1.0528893
[15] 1.5242409 1.3761019 0.9427032 0.6794809 1.4752693 0.7737512 1.0120797
[22] 0.8692458 1.2079660 1.0610513 0.8570029 0.9794319 1.0957395 0.8243552
[29] 0.4162586 1.4079334 1.0692132 1.1059419

stA1

 [1] -0.9126354 -0.8331680 -1.0239203 -0.3721959 -0.5311308  0.7564474
 [7] -1.1828933 -1.2146727 -0.8172593 -0.9921410 -0.5152602 -0.9285442
[13] -0.4198840 -0.9444529 -0.4198840 -0.8331680  1.2810163  1.4081718
[19]  1.7102091  2.3460247  1.3806653  1.3127957  1.2333282  1.4240806
[25] -0.1337555 -0.1973142  0.2954372 -0.1337555 -0.4039753 -0.3880665
[31]  0.2795666 -0.2291317

stA2

 [1] -0.2292617 -0.4917962 -0.6437899 -1.2241293 -0.3398026 -2.0946384
 [7] -1.0721356 -1.2655821 -1.3484877 -1.8873744 -0.7543307 -0.9615948
[13] -0.3674378  0.4483537  0.8761467 -0.8786892  0.5312593  1.1524988
[19]  0.3234425 -0.4088906  0.5102565  1.1945044  1.7748438  0.6827002
[25]  0.6418001  1.1801340  0.4207184  0.8076114  0.9181522  0.6827002
[31]  0.9037819  0.9181522

stA3

 [1]  0.86459627 -0.23416149 -2.00372671  0.04161491  0.78881988 -2.50869565
 [7] -0.02608696 -0.84161491 -0.95465839 -0.28012422  0.47080745  0.07577640
[13]  0.84223602  0.24472050  2.83975155  0.43043478 -0.75652174 -0.92795031
[19]  0.29192547 -0.78633540 -0.78385093 -0.51242236  0.59627329  0.19068323
[25]  0.02919255  1.17018634 -0.19440994  0.68385093  1.08881988 -0.28385093
[31] -0.71118012  1.06583851

[Variables from the model B]

rB

 [1] 1.5385568 1.5885100 1.3587255 0.8991566 1.4086787 0.3097095 0.9191378
 [8] 0.3996252 0.7393065 0.6993440 1.2488286 1.4186693 1.4586318 1.8282851
[15] 0.8991566 0.9790816 1.0889785 1.0090535 0.7792690 0.8991566 0.8791753
[22] 0.7892597 0.6294096 0.9690910 1.0689973 0.5994377 0.6793628 0.7293159
[29] 0.9690910 0.7393065 0.7193253 1.7583507

stB1

 [1] -0.67898627 -0.94275552 -1.32045796  0.03417996 -1.18276552  2.01872951
 [7] -1.75937865 -1.85016395 -0.70319013 -0.89159673 -0.35055299 -0.38890124
[13] -0.81445562 -0.98941255 -0.95548269 -0.63066192  0.52759406  1.27063302
[19]  1.19746568  1.34424498  0.62679931  1.15103096  1.24195520  0.94395043
[25]  0.20232868  0.71085978  0.53654199  0.67470683  0.41377202  0.38428833
[31]  0.58178180 -0.40626910

stB2

 [1]  2.18599646  1.64030436  0.29913150 -0.30874645  2.29052340 -2.13238029
 [7] -0.78386750 -0.53233418 -0.96552917 -1.00046883 -0.02227346 -0.71399585
[13]  0.42490201  1.27034048  0.09650296 -0.32970563 -0.23188840 -0.24586119
[19]  0.04061179 -0.07118592 -0.49040812 -0.04323265 -0.06419952 -0.18297594
[25]  0.40393513 -0.73495504 -0.53233418 -0.23188840  0.13144263 -0.21092921
[31] -1.24501576  2.29052340

stB3

 [1] -0.368  0.3416667 -1.788 -1.813 -0.617  0.