Re: [R] SPlus to R
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.
Re: [R] SPlus to R
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.741 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 From: William Dunlap wdun...@tibco.com @r-project.org Sent: Wednesday, October 5, 2011 11:25 AM Subject: RE: [R] SPlus to R I think you only have to change the multi-argument returns to call list. You can remove the name from the single argument return, as it will be ignore return(name=value) - return(value) return(n1=v1, n2=v2) - return(list(n1=v1, n2=v2)) (I say I think because I don't have easy access to S+ 4.5, from 1999 or so, to check this out.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap Sent: Wednesday, October 05, 2011 9:09 AM To: Scott Raynaud; r-help@r-project.org Subject: Re: [R] SPlus to R It looks like this code was written for S+ 4.5 (aka '2000') or before, which was based on S version 3. Try changing return(name1=value1, name2=value2) to return(list(name1=value1, name2=value2)) In S+ from 5.0 onwards return(name=value) or return(name1=value1, name2
Re: [R] SPlus to R
On Oct 6, 2011, at 11:17 AM, Scott Raynaud wrote: I'm re-posting this since it did not appear at the end of the thread. Sorry for the inconvenience. Not sure why it's giving the message: An embedded and charset-unspecified text was scrubbed... As far as I know my replies are set up as text and not html. As far as I can tell but have not been able to find this well- documented, the test being applied is not to the content of an attachment but rather to the extension of the attachment's name. If it is not something.txt or something_else.pdf, it's probably going to fail the server test and be scrubbed. Files with extensions .csv or .dat will generally fail, despite being text formats. -- David Winsemius, MD West Hartford, CT __ 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.
Re: [R] SPlus to R
Hi Scott, I am not familiar with S-Plus (though many aspects are quite similar to R). I will say that your function looks approximately correct. I am not familiar with the ss.rand function. I searched, and found some things that I suspect are similar in the packages MBESS, but without knowing more about it from S-Plus, it is tough to make a testable example. Do you have access to S-Plus? Can you provide more information about this function, what it does, what is like, etc.? There are some active members of this list who are quite familiar with S-Plus so one of them may be more insightful. Cheers, Josh On Tue, Oct 4, 2011 at 6:53 PM, Scott Raynaud scott.rayn...@yahoo.com wrote: I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator -. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Here is the entire output: ## sshc.ssc: sample size calculation for historical control studies ## J. Jack Lee (jj...@mdanderson.org) and Chi-hong Tseng ## Department of Biostatistics, Univ. of Texas M.D. Anderson Cancer Center ## ## 3/1/99 ## updated 6/7/00: add loess ##-- Required Input: # # 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: # # alpha size of the test # power desired power of the test # tol convergence criterion for methods 1 2 in terms of sample size # tol1 convergence criterion for method 3 at any given obs Rc in terms of difference # of expected power from target # tol2 overall convergence criterion for method 3 as the max absolute deviation # of expected power from target for all Rc # cc range of multiplicative constant applied to the initial values ne # l.span smoothing constant for loess # # Note: rc is required for methods 1 and 2 but not 3 # method 3 return the sample size need for rc=0 to (1-d)*nc # Output # for methdos 1 2: return the sample size needed for the experimental group (1 number) # for given rc, nc, d, alpha, and power # for method 3: return the profile of sample size needed for given nc, d, alpha, and power # vector $ne contains the sample size corresponding to rc=0, 1, 2, ... nc*(1-d) # vector $Ep contains the expected power corresponding to # the true pc = (0, 1, 2, ..., nc*(1-d)) / nc # #-- sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, + tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) + { + ### for method 1 + if (method==1) { + ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) + return(ne=ne1) + } + ### for method 2 + if (method==2) { + ne-nc + ne1-nc+50 + while(abs(ne-ne1)tol ne110){ + ne-ne1 + pe-d+rc/nc + ne1-nef(rc,nc,pe*ne,ne,alpha,power) + ## if(is.na(ne1)) print(paste('rc=',rc,',nc=',nc,',pe=',pe,',ne=',ne)) + } + if (ne110) return(NA) + else return(ne=ne1) + } + ### 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) + ### check overall absolute deviance + old.abs.dev-sum(abs(ans$Ep-power)) + ##bad-0 + print(round(ans$Ep,4)) + print(round(ans$ne,2)) + lines(pc,ans$ne,lty=1,col=8) + old.ne-ans$ne + ##while(max(abs(ans$Ep-power))tol2 bad==0){ unnecessary ## +
Re: [R] SPlus to R
When R was invented, nearly all of the core R functions were written to produce exactly the same answers as those returned by S-Plus. Some very minor exceptions were made for time series functions, for example, where better algorithms in R produced slightly better fits. There may be other, less benign examples, but none come to mind at the moment. Some of the core R functions have arguments that were not available in S-Plus at the time they were written. For example, probability functions included log and lower.tail arguments that, if my memory is correct, were not available in S-Plus at that time. More recent versions of S-Plus can reportedly run R scripts and packages without change. One set of examples comes to mind where you can find subtle differences between S-Plus and R: If you get Pinheiro and Bates (2000) Mixed-Effects Models in S and S-Plus (Springer) and try to run the code exactly as written in the book, you may get the answers in the book under S-Plus but not in a few cases in R. However, the nlme package companion to the book includes a scripts directory containing files required to obtain all the results in that book. In most cases, the functions and syntax, etc., are exactly the same in S-Plus and R. However, there are a very few cases where the answers are NOT the same, because some defaults have changed. I don't remember the details now. If you have an S-Plus script in which you replaced _ by -, that should take care of most if not all of the required conversion. However, you need to check. If it breaks when you try to run it, find where it breaks, read the documentation and try to understand why it breaks and how to fix it. The dubug function in R can help immensely with this: If you say debug(fn), then each time fn is called, it will stop and allow you to walk through fn line by line evaluating what it does, even changing the code and values of variables on the fly if you like. This can help you fix anything that breaks AND understand whether you are still getting the correct answer. Hope this helps. Spencer On 10/4/2011 11:08 PM, Joshua Wiley wrote: Hi Scott, I am not familiar with S-Plus (though many aspects are quite similar to R). I will say that your function looks approximately correct. I am not familiar with the ss.rand function. I searched, and found some things that I suspect are similar in the packages MBESS, but without knowing more about it from S-Plus, it is tough to make a testable example. Do you have access to S-Plus? Can you provide more information about this function, what it does, what is like, etc.? There are some active members of this list who are quite familiar with S-Plus so one of them may be more insightful. Cheers, Josh On Tue, Oct 4, 2011 at 6:53 PM, Scott Raynaudscott.rayn...@yahoo.com wrote: I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator-. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Here is the entire output: ## sshc.ssc: sample size calculation for historical control studies ## J. Jack Lee (jj...@mdanderson.org) and Chi-hong Tseng ## Department of Biostatistics, Univ. of Texas M.D. Anderson Cancer Center ## ## 3/1/99 ## updated 6/7/00: add loess ##-- Required Input: # # 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: # # alpha size of the test # power desired power of the test # tolconvergence criterion for methods 1 2 in terms of sample size # tol1 convergence criterion for method 3 at any given obs Rc in terms of difference # of expected
Re: [R] SPlus to R
I had thought that the problem might be: return(ne=ne1) since R doesn't support that any more. But when I tried it, I got results (just without the name on the output). Better would be to change that line to: list(ne=ne1) ('return' is seldom necessary in either R or S+.) I'd suggest putting 'print' or 'cat' statements in to try to figure out where things go wrong. You'll find other hints in 'S Poetry' and 'The R Inferno'. There might be positive probability that at least one of those hints will be useful. Both those are available on www.burns-stat.com On 05/10/2011 02:53, Scott Raynaud wrote: I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator-. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Here is the entire output: ## sshc.ssc: sample size calculation for historical control studies ## J. Jack Lee (jj...@mdanderson.org) and Chi-hong Tseng ## Department of Biostatistics, Univ. of Texas M.D. Anderson Cancer Center ## ## 3/1/99 ## updated 6/7/00: add loess ##-- Required Input: # # 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: # # alpha size of the test # power desired power of the test # tolconvergence criterion for methods 1 2 in terms of sample size # tol1 convergence criterion for method 3 at any given obs Rc in terms of difference # of expected power from target # tol2 overall convergence criterion for method 3 as the max absolute deviation # of expected power from target for all Rc # cc range of multiplicative constant applied to the initial values ne # l.span smoothing constant for loess # # Note: rc is required for methods 1 and 2 but not 3 #method 3 return the sample size need for rc=0 to (1-d)*nc # Output # for methdos 1 2: return the sample size needed for the experimental group (1 number) #for given rc, nc, d, alpha, and power # for method 3: return the profile of sample size needed for given nc, d, alpha, and power #vector $ne contains the sample size corresponding to rc=0, 1, 2, ... nc*(1-d) #vector $Ep contains the expected power corresponding to # the true pc = (0, 1, 2, ..., nc*(1-d)) / nc # #-- sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, + tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) + { + ### for method 1 + if (method==1) { + ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) + return(ne=ne1) +} + ### for method 2 + if (method==2) { + ne-nc + ne1-nc+50 + while(abs(ne-ne1)tol ne110){ + ne-ne1 + pe-d+rc/nc + ne1-nef(rc,nc,pe*ne,ne,alpha,power) + ## if(is.na(ne1)) print(paste('rc=',rc,',nc=',nc,',pe=',pe,',ne=',ne)) + } + if (ne110) return(NA) + else return(ne=ne1) + } + ### 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) + ### check overall absolute deviance + old.abs.dev-sum(abs(ans$Ep-power)) + ##bad-0 + print(round(ans$Ep,4)) + print(round(ans$ne,2)) + lines(pc,ans$ne,lty=1,col=8) + old.ne-ans$ne + ##while(max(abs(ans$Ep-power))tol2 bad==0){ unnecessary ## + while(max(abs(ans$Ep-power))tol2){ + ans-c.searchd(nc, d, ans$ne, alpha, power, cc, tol1) + abs.dev-sum(abs(ans$Ep-power)) + print(paste( old.abs.dev=,old.abs.dev)) + print(paste( abs.dev=,abs.dev)) +
Re: [R] SPlus to R
On Wed, Oct 5, 2011 at 2:53 AM, Scott Raynaud scott.rayn...@yahoo.com wrote: I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator -. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Long shot: the code you posted looked like (and hard to tell without indentation) just a bunch of function definitions. R won't actually do anything unless you call those functions with some parameters. So, when you say you get no output when you 'run' the code, what exactly do you mean by 'run' the code? What I would do is: 1. Put the code in a file called 'whatever.R'. 2. Start R, and do source(whatever.R). That defines the functions. do ls() and you should see them. 3. Call one of the functions: sshc(100,10) I'd call that, in R terms, calling the sshc function rather than running anything. Barry __ 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.
Re: [R] SPlus to R
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). Thanks agian for your help. From: Barry Rowlingson b.rowling...@lancaster.ac.uk Cc: r-help@r-project.org r-help@r-project.org Sent: Wednesday, October 5, 2011 4:02 AM Subject: Re: [R] SPlus to R te: I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator -. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Long shot: the code you posted looked like (and hard to tell without indentation) just a bunch of function definitions. R won't actually do anything unless you call those functions with some parameters. So, when you say you get no output when you 'run' the code, what exactly do you mean by 'run' the code? What I would do is: 1. Put the code in a file called 'whatever.R'. 2. Start R, and do source(whatever.R). That defines the functions. do ls() and you should see them. 3. Call one of the functions: sshc(100,10) I'd call that, in R terms, calling the sshc function rather than running anything. 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.
Re: [R] SPlus to R
On 10/05/2011 07:44 AM, Scott Raynaud wrote: 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 convexEpowernef 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? As another poster suggested, use list(ne = ne, Ep = Ep1) instead of the the present return(). 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). Thanks agian for your help. From: Barry Rowlingsonb.rowling...@lancaster.ac.uk Cc: r-help@r-project.orgr-help@r-project.org Sent: Wednesday, October 5, 2011 4:02 AM Subject: Re: [R] SPlus to R te: I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator-. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Long shot: the code you posted looked like (and hard to tell without indentation) just a bunch of function definitions. R won't actually do anything unless you call those functions with some parameters. So, when you say you get no output when you 'run' the code, what exactly do you mean by 'run' the code? What I would do is: 1. Put the code in a file called 'whatever.R'. 2. Start R, and do source(whatever.R). That defines the functions. do ls() and you should see them. 3. Call one of the functions: sshc(100,10) I'd call that, in R terms, calling the sshc function rather than running anything. Barry -- Kevin E. Thorpe Biostatistician/Trialist, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 __ 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.
Re: [R] SPlus to R
On 05.10.2011 13:44, Scott Raynaud wrote: 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 convexEpowernef 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? No: return(list(ne = ne, Ep = Ep1)) Uwe 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). Thanks agian for your help. From: Barry Rowlingsonb.rowling...@lancaster.ac.uk Cc: r-help@r-project.orgr-help@r-project.org Sent: Wednesday, October 5, 2011 4:02 AM Subject: Re: [R] SPlus to R te: I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator-. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Long shot: the code you posted looked like (and hard to tell without indentation) just a bunch of function definitions. R won't actually do anything unless you call those functions with some parameters. So, when you say you get no output when you 'run' the code, what exactly do you mean by 'run' the code? What I would do is: 1. Put the code in a file called 'whatever.R'. 2. Start R, and do source(whatever.R). That defines the functions. do ls() and you should see them. 3. Call one of the functions: sshc(100,10) I'd call that, in R terms, calling the sshc function rather than running anything. 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. __ 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.
Re: [R] SPlus to R
On Wed, Oct 5, 2011 at 12:44 PM, Scott Raynaud scott.rayn...@yahoo.com wrote: 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 __ 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.
Re: [R] SPlus to R
It looks like this code was written for S+ 4.5 (aka '2000') or before, which was based on S version 3. Try changing return(name1=value1, name2=value2) to return(list(name1=value1, name2=value2)) In S+ from 5.0 onwards return(name=value) or return(name1=value1, name2=value2) throws away the names and in R return only takes a single object (and also ignores the name). The c.search function in your code ends with return(ne=ne, Ep=Ep1) and the code calling c.search() acts as though the writer expects that function to return list(ne=ne, Ep=Ep1) ans - c.searchd(nc, d, ne, alpha, power, cc, tol1) ... old.ne - ans$ne Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Scott Raynaud Sent: Tuesday, October 04, 2011 6:53 PM To: r-help@r-project.org Subject: [R] SPlus to R I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S- Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator -. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Here is the entire output: ## sshc.ssc: sample size calculation for historical control studies ## J. Jack Lee (jj...@mdanderson.org) and Chi-hong Tseng ## Department of Biostatistics, Univ. of Texas M.D. Anderson Cancer Center ## ## 3/1/99 ## updated 6/7/00: add loess ##-- Required Input: # # 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: # # alpha size of the test # power desired power of the test # tol convergence criterion for methods 1 2 in terms of sample size # tol1 convergence criterion for method 3 at any given obs Rc in terms of difference # of expected power from target # tol2 overall convergence criterion for method 3 as the max absolute deviation # of expected power from target for all Rc # cc range of multiplicative constant applied to the initial values ne # l.span smoothing constant for loess # # Note: rc is required for methods 1 and 2 but not 3 # method 3 return the sample size need for rc=0 to (1-d)*nc # Output # for methdos 1 2: return the sample size needed for the experimental group (1 number) # for given rc, nc, d, alpha, and power # for method 3: return the profile of sample size needed for given nc, d, alpha, and power # vector $ne contains the sample size corresponding to rc=0, 1, 2, ... nc*(1-d) # vector $Ep contains the expected power corresponding to # the true pc = (0, 1, 2, ..., nc*(1-d)) / nc # #-- sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, + tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) + { + ### for method 1 + if (method==1) { + ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) + return(ne=ne1) + } + ### for method 2 + if (method==2) { + ne-nc + ne1-nc+50 + while(abs(ne-ne1)tol ne110){ + ne-ne1 + pe-d+rc/nc + ne1-nef(rc,nc,pe*ne,ne,alpha,power) + ## if(is.na(ne1)) print(paste('rc=',rc,',nc=',nc,',pe=',pe,',ne=',ne)) + } + if (ne110) return(NA) + else return(ne=ne1) + } + ### 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
Re: [R] SPlus to R
I think you only have to change the multi-argument returns to call list. You can remove the name from the single argument return, as it will be ignore return(name=value) - return(value) return(n1=v1, n2=v2) - return(list(n1=v1, n2=v2)) (I say I think because I don't have easy access to S+ 4.5, from 1999 or so, to check this out.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap Sent: Wednesday, October 05, 2011 9:09 AM To: Scott Raynaud; r-help@r-project.org Subject: Re: [R] SPlus to R It looks like this code was written for S+ 4.5 (aka '2000') or before, which was based on S version 3. Try changing return(name1=value1, name2=value2) to return(list(name1=value1, name2=value2)) In S+ from 5.0 onwards return(name=value) or return(name1=value1, name2=value2) throws away the names and in R return only takes a single object (and also ignores the name). The c.search function in your code ends with return(ne=ne, Ep=Ep1) and the code calling c.search() acts as though the writer expects that function to return list(ne=ne, Ep=Ep1) ans - c.searchd(nc, d, ne, alpha, power, cc, tol1) ... old.ne - ans$ne Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Scott Raynaud Sent: Tuesday, October 04, 2011 6:53 PM To: r-help@r-project.org Subject: [R] SPlus to R I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S- Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator -. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Here is the entire output: ## sshc.ssc: sample size calculation for historical control studies ## J. Jack Lee (jj...@mdanderson.org) and Chi-hong Tseng ## Department of Biostatistics, Univ. of Texas M.D. Anderson Cancer Center ## ## 3/1/99 ## updated 6/7/00: add loess ##-- Required Input: # # 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: # # alpha size of the test # power desired power of the test # tol convergence criterion for methods 1 2 in terms of sample size # tol1 convergence criterion for method 3 at any given obs Rc in terms of difference # of expected power from target # tol2 overall convergence criterion for method 3 as the max absolute deviation # of expected power from target for all Rc # cc range of multiplicative constant applied to the initial values ne # l.span smoothing constant for loess # # Note: rc is required for methods 1 and 2 but not 3 # method 3 return the sample size need for rc=0 to (1-d)*nc # Output # for methdos 1 2: return the sample size needed for the experimental group (1 number) # for given rc, nc, d, alpha, and power # for method 3: return the profile of sample size needed for given nc, d, alpha, and power # vector $ne contains the sample size corresponding to rc=0, 1, 2, ... nc*(1-d) # vector $Ep contains the expected power corresponding to # the true pc = (0, 1, 2, ..., nc*(1-d)) / nc # #-- sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, + tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5
Re: [R] SPlus to R
On Wed, Oct 5, 2011 at 4:54 PM, Scott Raynaud scott.rayn...@yahoo.com wrote: 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. The sshc(10,100) was just some numbers I plucked out of nowhere. Your definition: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, + tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) actually probably only needs the first value, the other parameters will take the defaults. sshc(10) should minimally run. [[pedantic note I say probably because R code can look like this: foo = function(x){ if(missing(x)){x = 99} ... } which is the same as foo = function(x=99){...} - so just because there's no default in the function definition it doesn't mean you have to supply it. end pedantic note]] Not sure why you have to click 'stop' - it might be that there's a couple of 'while' loops in there which might not be terminating. There's what looks like some debugging calls to 'cat' commented out - if you uncomment them you'll see what's going on, but you might not see them as they happen in Windows since I dont think the output isn't normally flushed immediately. There's probably an option you can set or a flush function you can call Barry __ 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.
Re: [R] SPlus to R
I took the original code, changed all return() calls of the form return(n1=v1,n2=v2) to return(list(n1=v1,n2=v2)) and then sshc(10,100) chugged away and produced some plots and returned something with no errors. It took a couple of minutes. I also changed T-TRUE and F-FALSE, as that makes the code a safer to use in R, where TRUE is a reserved word but T is not. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Barry Rowlingson Sent: Wednesday, October 05, 2011 11:08 AM To: Scott Raynaud Cc: r-help@r-project.org Subject: Re: [R] SPlus to R On Wed, Oct 5, 2011 at 4:54 PM, Scott Raynaud scott.rayn...@yahoo.com wrote: 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. The sshc(10,100) was just some numbers I plucked out of nowhere. Your definition: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, + tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) actually probably only needs the first value, the other parameters will take the defaults. sshc(10) should minimally run. [[pedantic note I say probably because R code can look like this: foo = function(x){ if(missing(x)){x = 99} ... } which is the same as foo = function(x=99){...} - so just because there's no default in the function definition it doesn't mean you have to supply it. end pedantic note]] Not sure why you have to click 'stop' - it might be that there's a couple of 'while' loops in there which might not be terminating. There's what looks like some debugging calls to 'cat' commented out - if you uncomment them you'll see what's going on, but you might not see them as they happen in Windows since I dont think the output isn't normally flushed immediately. There's probably an option you can set or a flush function you can call Barry __ 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@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.
Re: [R] SPlus to R
Ok, I chased down all the problems. This is my last output: sshc(100,10) [1] 0.8000 0.7908 0.7844 0.7773 0.7785 0.7989 [1] 5.37 10.29 13.27 13.04 9.66 3.54 [1] old.abs.dev= 0.0701944484789673 [1] abs.dev= 0.034407699378335 [1] 0.8000 0.8030 0.8057 0.8041 0.8035 0.8180 [1] 5.37 10.87 14.73 15.32 11.74 3.85 [1] old.abs.dev= 0.034407699378335 [1] abs.dev= 0.00908198716779307 [1] 0.8000 0.7989 0.7994 0.7979 0.7950 0.7998 [1] 5.37 10.69 14.16 14.63 11.49 3.48 [1] old.abs.dev= 0.00908198716779307 [1] abs.dev= 0.00616028545602321 [1] 0.8000 0.8000 0.8011 0.8011 0.7989 0.8028 [1] 5.37 10.77 14.25 14.74 11.93 3.53 $ne [1] 5.369543 10.769265 14.252492 14.743598 11.928704 3.533269 $Ep [1] 0.7999630 0.8000404 0.8010525 0.8011409 0.7988643 0.8027538 There were 15 warnings (use warnings() to see them) warnings() Warning messages: 1: span too small. fewer data values than degrees of freedom. 2: pseudoinverse used at -0.0025 3: neighborhood radius 0.2025 4: reciprocal condition number 0 5: There are other near singularities as well. 0.041006 6: span too small. fewer data values than degrees of freedom. 7: pseudoinverse used at -0.0025 8: neighborhood radius 0.2025 9: reciprocal condition number 0 10: There are other near singularities as well. 0.041006 11: span too small. fewer data values than degrees of freedom. 12: pseudoinverse used at -0.0025 13: neighborhood radius 0.2025 14: reciprocal condition number 0 15: There are other near singularities as well. 0.041006 Are my problems with syntax or the algorithm or the call sshc(100,10)? I still don't understand what the arguments in the call mean. Thanks. From: Uwe Ligges lig...@statistik.tu-dortmund.de Cc: Barry Rowlingson b.rowling...@lancaster.ac.uk; r-help@r-project.org r-help@r-project.org Sent: Wednesday, October 5, 2011 8:03 AM Subject: Re: [R] SPlus to R On 05.10.2011 13:44, Scott Raynaud wrote: 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? No: return(list(ne = ne, Ep = Ep1)) Uwe 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). Thanks agian for your help. From: Barry Rowlingsonb.rowling...@lancaster.ac.uk Cc: r-help@r-project.orgr-help@r-project.org Sent: Wednesday, October 5, 2011 4:02 AM Subject: Re: [R] SPlus to R te: I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator-. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Long shot: the code you posted looked like (and hard to tell without indentation) just a bunch of function definitions. R won't actually do anything unless you call those functions with some parameters. So, when you say you get no output when you 'run' the code, what exactly do you mean by 'run' the code? What I would do is: 1. Put the code in a file called 'whatever.R'. 2. Start R, and do source(whatever.R). That defines the functions. do ls() and you should see them. 3. Call one of the functions: sshc(100,10) I'd call that, in R terms, calling the sshc function rather than running anything. 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. [[alternative
Re: [R] SPlus to R
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.
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 On Wed, Oct 5, 2011 at 8:54 AM, Scott Raynaud scott.rayn...@yahoo.comwrote: 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 convexEpowernef 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: # rcnumber of response in historical control group # ncsample 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.
[R] SPlus to R
I'm trying to convert an S-Plus program to R. Since I'm a SAS programmer I'm not facile is either S-Plus or R, so I need some help. All I did was convert the underscores in S-Plus to the assignment operator -. Here are the first few lines of the S-Plus file: sshc _ function(rc, nc, d, method, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1 _ ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } My translation looks like this: sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) { ### for method 1 if (method==1) { ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) return(ne=ne1) } The program runs without throwing errors, but I'm not getting any ourput in the console. This is where it should be, right? I think I have this set up correctly. I'm using method=3 which only requires nc and d to be specified. Any ideas why I'm not seeing output? Here is the entire output: ## sshc.ssc: sample size calculation for historical control studies ## J. Jack Lee (jj...@mdanderson.org) and Chi-hong Tseng ## Department of Biostatistics, Univ. of Texas M.D. Anderson Cancer Center ## ## 3/1/99 ## updated 6/7/00: add loess ##-- Required Input: # # 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: # # alpha size of the test # power desired power of the test # tol convergence criterion for methods 1 2 in terms of sample size # tol1 convergence criterion for method 3 at any given obs Rc in terms of difference # of expected power from target # tol2 overall convergence criterion for method 3 as the max absolute deviation # of expected power from target for all Rc # cc range of multiplicative constant applied to the initial values ne # l.span smoothing constant for loess # # Note: rc is required for methods 1 and 2 but not 3 # method 3 return the sample size need for rc=0 to (1-d)*nc # Output # for methdos 1 2: return the sample size needed for the experimental group (1 number) # for given rc, nc, d, alpha, and power # for method 3: return the profile of sample size needed for given nc, d, alpha, and power # vector $ne contains the sample size corresponding to rc=0, 1, 2, ... nc*(1-d) # vector $Ep contains the expected power corresponding to # the true pc = (0, 1, 2, ..., nc*(1-d)) / nc # #-- sshc-function(rc, nc=500, d=.5, method=3, alpha=0.05, power=0.8, + tol=0.01, tol1=.0001, tol2=.005, cc=c(.1,2), l.span=.5) + { + ### for method 1 + if (method==1) { + ne1-ss.rand(rc,nc,d,alpha=.05,power=.8,tol=.01) + return(ne=ne1) + } + ### for method 2 + if (method==2) { + ne-nc + ne1-nc+50 + while(abs(ne-ne1)tol ne110){ + ne-ne1 + pe-d+rc/nc + ne1-nef(rc,nc,pe*ne,ne,alpha,power) + ## if(is.na(ne1)) print(paste('rc=',rc,',nc=',nc,',pe=',pe,',ne=',ne)) + } + if (ne110) return(NA) + else return(ne=ne1) + } + ### 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) + ### check overall absolute deviance + old.abs.dev-sum(abs(ans$Ep-power)) + ##bad-0 + print(round(ans$Ep,4)) + print(round(ans$ne,2)) + lines(pc,ans$ne,lty=1,col=8) + old.ne-ans$ne + ##while(max(abs(ans$Ep-power))tol2 bad==0){ unnecessary ## + while(max(abs(ans$Ep-power))tol2){ + ans-c.searchd(nc, d, ans$ne, alpha, power, cc, tol1) + abs.dev-sum(abs(ans$Ep-power)) + print(paste( old.abs.dev=,old.abs.dev)) + print(paste( abs.dev=,abs.dev)) + ##if (abs.dev old.abs.dev) { bad-1} + old.abs.dev-abs.dev + print(round(ans$Ep,4)) + print(round(ans$ne,2)) + lines(pc,old.ne,lty=1,col=1) + lines(pc,ans$ne,lty=1,col=8) + ### add convex + ans$ne-convex(pc,ans$ne)$wy + ### add loess + ###old.ne-ans$ne + loess.ne-loess(ans$ne ~ pc, span=l.span) + lines(pc,loess.ne$fit,lty=1,col=4) + old.ne-loess.ne$fit + ###readline() + } + return(ne=ans$ne, Ep=ans$Ep) + } + } ## needed for method 1 nef2-function(rc,nc,re,ne,alpha,power){ +
[R] 5 Courses*** R/Splus Fundamentals R Advanced Programming: March - April 2009 at USA locations by XLSolutions Corp
XLSolutions Corporation (www.xlsolutions-corp.com) is proud to announce our*** R/Splus Fundamentals and Programming Techniques and R Advanced Programming***courses at USA locations for March - April 2009. (1) R/Splus Fundamentals and Programming Techniques http://www.xlsolutions-corp.com/rplus.asp * New York City ** March 19-20, 2009 * San Francisco ** March 16-17, 2009 (2) R/Splus Advanced Programming http://www.xlsolutions-corp.com/rplus.asp * San Francisco ** April 27-28, 2009 * Boston ** April 22-23, 2009 * New York City ** April 20-21, 2009 Ask for group discount and reserve your seat Now - Earlybird Rates. Payment due after the class! Email Sue Turner: s...@xlsolutions-corp.com Phone: 206-686-1578 Please let us know if you and your colleagues are interested in this class to take advantage of group discount. Register now to secure your seat! Cheers, Elvis Miller, PhD Manager Training. XLSolutions Corporation 206 686 1578 www.xlsolutions-corp.com el...@xlsolutions-corp.com __ 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] Courses*** R/Splus Fundamentals R Advanced Programming: November - December 2008 at 3 locations by XLSolutions Corp
XLSolutions Corporation (www.xlsolutions-corp.com) is proud to announce our*** R/Splus Fundamentals and Programming Techniques and R Advanced Programming***courses at 3 USA locations for November - December 2008. (1) R/Splus Fundamentals and Programming Techniques http://www.xlsolutions-corp.com/rplus.asp * New York City ** November 20-21, 2008 * San Francisco ** December 15-16, 2008 (2) R/Splus Advanced Programming http://www.xlsolutions-corp.com/rplus.asp * San Francisco ** December 18-19, 2008 Ask for group discount and reserve your seat Now - Earlybird Rates. Payment due after the class! Email Sue Turner: [EMAIL PROTECTED] Phone: 206-686-1578 Please let us know if you and your colleagues are interested in this class to take advantage of group discount. Register now to secure your seat! Cheers, Elvis Miller, PhD Manager Training. XLSolutions Corporation 206 686 1578 www.xlsolutions-corp.com [EMAIL PROTECTED] __ 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.