I did some testing and I believe the program is operating properly.  It takes 
some time to finish, especially as sample sizes get larger, but I seem to be 
able to reproduce the results from the original paper.  Right now I'm most 
interested in method 3.  I set nc=40 and d=.2 as in the paper.  The results are 
below.  The program iterates to find a solution and the more subjects (nc), the 
more iterations it needs.  The initial pass uses estimates from the randomized 
method as starting values and this is plotted in black on a graph.  The next 
pass uses the algorithm to generate sample size estimates which are plotted in 
gray on the first pass.  Each new estimate is plotted in dark blue as the 
previous one turns black.  This reults in several curves being plotted but one 
can get an idea of the relevant one by looking for the blue plot and examining 
the $ne vector below.
 
Reading the graph is more troublesome as nc increases.  It takes many more 
iterations to complete and the graph gets quite crowded.  I'm not sure what the 
best solution is.  Which would be easiest?
 
1) Plot ne against pc for the final iteration.  The problem here is pc is not 
saved in a vector.
2) Cut and paste $ne into Excel and re-create the corresponding pc's.
 
It's not clear to me how pc is incremented.  Seems like it's in the code block 
below:
 
### for method 3
if (method==3) {
if (tol1 > tol2/10) tol1<-tol2/10
ncstar<-(1-d)*nc
pc<-(0:ncstar)/nc
ne<-rep(NA,ncstar + 1)
for (i in (0:ncstar))
{ ne[i+1]<-ss.rand(i,nc,d,alpha=.05,power=.8,tol=.01)
}
plot(pc,ne,type='l',ylim=c(0,max(ne)*1.5))
ans<-c.searchd(nc, d, ne, alpha, power, cc, tol1)

 
> sshc()
 [1] 0.8000 0.7889 0.7825 0.7786 0.7763 0.7751 0.7747 0.7750 0.7759 0.7772
[11] 0.7790 0.7815 0.7852 0.7899 0.7943 0.7968 0.7979 0.7989 0.8002 0.8021
[21] 0.8045 0.8072 0.8100 0.8123 0.8137 0.8137 0.8124 0.8105 0.8095 0.8103
[31] 0.8134 0.8180 0.8244
 [1]  11.64  19.62  27.50  36.44  46.54  58.19  71.81  87.93 107.30 130.38
[11] 158.47 192.34 235.47 291.93 370.48 471.26 569.17 626.36 626.18 588.94
[21] 529.27 459.67 389.30 323.70 263.50 210.58 164.26 124.25  90.49  63.23
[31]  42.13  26.23   8.13
[1] " old.abs.dev= 0.434571909427754"
[1] "     abs.dev= 0.259398042835904"
 [1] 0.8000 0.8031 0.8063 0.8094 0.8120 0.8140 0.8152 0.8156 0.8152 0.8141
[11] 0.8122 0.8097 0.8073 0.8055 0.8045 0.8037 0.8025 0.8015 0.8006 0.7995
[21] 0.7982 0.7969 0.7956 0.7946 0.7939 0.7930 0.7916 0.7897 0.7879 0.7872
[31] 0.7876 0.7886 0.7887
 [1]  11.64  20.91  30.51  42.13  56.19  73.71  95.59 123.29 159.20 204.83
[11] 263.66 337.90 424.41 520.76 623.55 727.31 804.98 810.60 733.27 621.58
[21] 504.83 397.60 310.92 242.78 190.93 151.72 120.81  95.24  72.67  52.84
[31]  36.01  22.42   6.32
[1] " old.abs.dev= 0.259398042835904"
[1] "     abs.dev= 0.160699574601494"
 [1] 0.8000 0.7985 0.7972 0.7958 0.7944 0.7930 0.7917 0.7907 0.7903 0.7907
[11] 0.7917 0.7929 0.7941 0.7951 0.7964 0.7977 0.7982 0.7984 0.7989 0.7995
[21] 0.8000 0.8006 0.8013 0.8023 0.8036 0.8048 0.8054 0.8055 0.8055 0.8063
[31] 0.8081 0.8103 0.8125
 [1]  11.64  20.56  29.46  39.64  51.27  64.86  80.67  99.46 122.30 149.90
[11] 184.62 230.35 286.04 352.93 429.63 508.43 588.14 635.70 616.86 561.50
[21] 489.16 408.17 333.63 269.21 215.86 173.66 139.24 110.43  84.50  61.28
[31]  41.38  25.49   7.42
[1] " old.abs.dev= 0.160699574601494"
[1] "     abs.dev= 0.0893104146067729"
 [1] 0.8000 0.8006 0.8013 0.8021 0.8029 0.8036 0.8043 0.8048 0.8050 0.8051
[11] 0.8049 0.8045 0.8037 0.8024 0.8019 0.8019 0.8015 0.8012 0.8010 0.8009
[21] 0.8007 0.8002 0.7995 0.7990 0.7987 0.7985 0.7980 0.7970 0.7958 0.7950
[31] 0.7950 0.7950 0.7939
 [1]  11.64  20.72  29.92  40.75  53.42  68.99  87.79 111.53 141.92 179.12
[11] 226.54 290.16 365.88 456.60 556.96 640.04 722.83 757.33 711.48 624.30
[21] 522.26 423.34 335.91 264.10 206.62 162.86 128.85 101.60  77.86  56.72
[31]  38.30  23.41   6.49
[1] " old.abs.dev= 0.0893104146067729"
[1] "     abs.dev= 0.0506515395975703"
 [1] 0.8000 0.7996 0.7994 0.7990 0.7986 0.7982 0.7978 0.7974 0.7970 0.7969
[11] 0.7970 0.7975 0.7981 0.7979 0.7982 0.7990 0.7991 0.7990 0.7990 0.7992
[21] 0.7994 0.7996 0.7996 0.7998 0.8002 0.8009 0.8015 0.8015 0.8014 0.8016
[31] 0.8025 0.8035 0.8041
 [1]  11.64  20.65  29.71  40.22  52.31  66.93  84.02 104.94 131.25 161.98
[11] 200.06 251.89 310.71 386.59 476.45 545.33 622.06 664.45 636.92 570.09
[21] 486.12 402.82 326.45 262.37 208.03 165.78 131.88 104.87  81.05  59.38
[31]  40.18  24.54   6.99
$ne
 [1]  11.637555  20.651336  29.710258  40.223468  52.314568  66.928887
 [7]  84.022673 104.936774 131.254491 161.981416 200.060785 251.890694
[13] 310.710449 386.591379 476.449601 545.327456 622.056417 664.447078
[19] 636.923065 570.091413 486.117837 402.817857 326.451672 262.370265
[25] 208.029592 165.777369 131.875077 104.873469  81.051410  59.379349
[31]  40.182140  24.544626   6.990464
$Ep
 [1] 0.7999941 0.7996387 0.7993605 0.7990384 0.7986411 0.7982104 0.7978227
 [8] 0.7974117 0.7970255 0.7969174 0.7970263 0.7974569 0.7980592 0.7979356
[15] 0.7982330 0.7989812 0.7991050 0.7990024 0.7990236 0.7992147 0.7994437
[22] 0.7995969 0.7996266 0.7997703 0.8002355 0.8009229 0.8014502 0.8015201
[29] 0.8013688 0.8016032 0.8025078 0.8035148 0.8040642

 

________________________________
From: Bert Gunter <gunter.ber...@gene.com>

Cc: r-help@r-project.org
Sent: Wednesday, October 5, 2011 2:25 PM
Subject: Re: [R] SPlus to R


Consider:

> f <- function(x){ x<- 10;x^2}
> f()
[1] 100

If the argument is not needed, there is no error in omitting it.
R uses "lazy evaluation" -- arguments are not evaluated until needed.

-- Bert




te:

It seems I have things set up correctly.  I suspect that the arguments 
sshc(100,10) are the isuue.  It seems that the 100,10 is not necessary since 
the code itself specifies the arguments.  It runs and produces a power curve if 
I simply type sshc() but it also seems to try to keep running somethng as I 
have to click stop to get back to a prompt in the console. 
> 
>Why specify 100,10?  There are 9 arguments, 3 which are required and the rest 
>optional.  Shouldn't I have to specify the 3 required arguments, nc, d and 
>method at a minimum?  It would look like sshc(nc=500, d=.5, method=3), right?  
>I;m still not sure, however, why that would be necessary since it's hard coded.
>
>
>________________________________
>From: Barry Rowlingson <b.rowling...@lancaster.ac.uk>
>
>Cc: "r-help@r-project.org" <r-help@r-project.org>
>Sent: Wednesday, October 5, 2011 9:27 AM
>Subject: Re: [R] SPlus to R
>
>
>ote:
>> Hope I did this right.  I repeated what I'd done before:
>>
>> 1) Opened script
>> 2) Selected run all (this produced my inital post
>>
>> Then as suggested I:
>>
>> 3) Typed ls()
>> 4) Saw that the function was present and issued sshc(100,10)
>>
>> Here's what I got:
>>
>>> ls()
>> [1] "c.searchd" "convex"    "Epower"    "nef"       "nef2"      "power1.f"
>> [7] "ss.rand"   "sshc"      "vertex"
>>> sshc(100,10)
>> Error in return(ne = ne, Ep = Ep1) :
>>   multi-argument returns are not permitted
>> So it looks like I need to change the return(ne = ne, Ep = Ep1) to two
>> separate lines, correct?
>>
>> On a brighter note, I did get a power curve as expected.  One thing I don't
>> understand is the meaning of the arguments in sshc(100,10).
>
>There are some comments in the function code that tell you:
>
># rc    number of response in historical control group
># nc    sample size in historical control
># d      target improvement = Pe - Pc
># method 1=method based on the randomized design
>#        2=Makuch & Simon method (Makuch RW, Simon RM. Sample size
>considerations
>#          for non-randomized comparative studies. J of Chron Dis
>1980; 3:175-181.
>#        3=uniform power method
>######## optional Input:
>
>- and so on.
>
>Beyond that, I'll have to defer to people who know what this is
>actually trying to compute...
>
>Also, its highly possible that this code has already been ported to R
>- lots of things have. If you know what its meant to compute then a
>quick search might get you running quicker.
>
>Barry
>       [[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.
>
>


-- 

"Men by nature long to get on to the ultimate truths, and will often be 
impatient with elementary studies or fight shy of them. If it were possible to 
reach the ultimate truths without the elementary studies usually prefixed to 
them, these would not be preparatory studies but superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics
        [[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.

Reply via email to