Re: [R] Hollander's test of bivariate symmetry
Couldn't find it anywhere, so for future users who stumble on this thread, here is some code. Note: If your data has missing values, delete those observations from the data first before running this code. Place these functions in the global environment (ie run the code below). Then, to obtain the test statistic: H_bisym_stat(x,y) (x and y are the two vectors you are comparing). To obtain a p-value: H_bisym_stat(x,y). The p-value is calculated via a Monte Carlo algorithm. You can use the permutations argument to H_bisym_stat to increase the number of Monte Carlo samples. #Hollander's test of bivariate symmetry #Calculating test statistic for Hollander's test of bivariate symmetry H_bisym_stat - function(x,y){ minXY - pmin(x,y); sortX - x[order(minXY)]; sortY - y[order(minXY)]; minXY - pmin(sortX, sortY); R - as.numeric(sortX = sortY); maxXY - pmax(sortX,sortY); D1 - matrix(0, length(x), length(x)); D2 - matrix(0, length(x), length(x)); for (i in 1:length(x)){ for (j in 1:length(x)){ D1[i,j] = as.numeric(minXY[j] maxXY[i] maxXY[i] = maxXY[j]); D2[i,j] = as.numeric(minXY[i] = minXY[j]); } } D = D1*D2; S = 2*R - 1; T = t( t(S) %*% D); H_squared = (1/length(x)^2)*( t(T) %*% T ); H_squared}; #Create a permutation sample for paired data; permsamp_paired - function(x,y){ new - rbinom(length(x),1,0.5); x_new - x*new + y*(1 - new); y_new - y*new + x*(1 - new); list(x_new = x_new, y_new = y_new)}; #Calculate pvalue for Hollander statistic; H_bisym_pv - function(x, y, permutations = 1000){ H_squared = H_bisym_stat(x=x, y=y); numb_greater = 0; for (i in 1:permutations) { newvars - permsamp_paired(x=x, y=y); x_new - newvars$x_new; y_new - newvars$y_new; newstat - H_bisym_stat(x=x_new, y=y_new); numb_greater = numb_greater + as.numeric(newstat = H_squared); } pv - numb_greater/permutations; pv }; Joe Boyer Statistical Sciences GlaxoSmithKline [[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] replying to old thread
If you come across an archived thread that you would like to reply to, how do you reply to it without starting a new thread? Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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] Hollander's test of bivariate symmetry
Does anyone know if any R package has a function that will conduct Hollander's test of bivariate symmetry? (Hollander, Biometrika, 1971) Either the exact test or an asymptotic version would be sufficient for my purposes. Thanks. Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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] RExcel waiting for OLE action
When I run a macro that uses RExcel, I get a dialog box that says Microsoft Excel is waiting for another application to complete an OLE action. There is no error in the RExcel commands in the macro, of that I am sure. The box appears to be related to the inclusion of RunRFile commands. The macro will run through the second RunRFile command, but will not execute the Worksheet.Pictures.Insert statements or the GetArray statements until the user clicks OK on the dialog box. Any insight into how I can avoid the dialog box would be appreciated. The macro is below. It's your basic, send-to-R, run R, retrieve-from-R macro. Call Rinterface.StartRServer Call Rinterface.RRun(rm(list = ls())) Call Rinterface.RRun(dev.off()) Call Rinterface.PutArray(mat1, Range(DATA_INPUT_OUTPUT!B7:I506)) Call Rinterface.PutArray(mat2, Range(DATA_INPUT_OUTPUT!J7:Q506)) Call Rinterface.PutArray(cpd, Range(DATA_INPUT_OUTPUT!A7:A506)) Call Rinterface.PutArray(name_of_assay_one, Range(DATA_INPUT_OUTPUT!B1)) Call Rinterface.PutArray(name_of_assay_two, Range(DATA_INPUT_OUTPUT!B2)) Call Rinterface.RunRFile(C:\Program Files\R\MDR Programs\AM_ACT_Macros.R) Call Rinterface.RunRFile(C:\Program Files\R\MDR Programs\AM_ACT.R) Worksheets(GRAPHS).Range(B58).Select Worksheets(GRAPHS).Range(B58).Clear Worksheets(GRAPHS).Pictures.Insert(C:\TEMP\var_means_both.jpg).Select Worksheets(GRAPHS).Range(B84).Select Worksheets(GRAPHS).Range(B84).Clear Worksheets(GRAPHS).Pictures.Insert(C:\TEMP\var_means_one.jpg).Select Worksheets(GRAPHS).Range(B110).Select Worksheets(GRAPHS).Range(B110).Clear Worksheets(GRAPHS).Pictures.Insert(C:\TEMP\var_means_two.jpg).Select Worksheets(GRAPHS).Range(B136).Select Worksheets(GRAPHS).Range(B136).Clear Worksheets(GRAPHS).Pictures.Insert(C:\TEMP\normality_one.jpg).Select Worksheets(GRAPHS).Range(B162).Select Worksheets(GRAPHS).Range(B162).Clear Worksheets(GRAPHS).Pictures.Insert(C:\TEMP\normality_two.jpg).Select Worksheets(GRAPHS).Range(B188).Select Worksheets(GRAPHS).Range(B188).Clear Worksheets(GRAPHS).Pictures.Insert(C:\TEMP\one_two.jpg).Select Worksheets(GRAPHS).Range(B214).Select Worksheets(GRAPHS).Range(B214).Clear Worksheets(GRAPHS).Pictures.Insert(C:\TEMP\pvalue_mean.jpg).Select Worksheets(GRAPHS).Range(B240).Select Worksheets(GRAPHS).Range(B240).Clear Worksheets(GRAPHS).Pictures.Insert(C:\TEMP\pvalue_hist.jpg).Select Call Rinterface.GetArray(pred_output$quant_one, Range(ASYM_MAX_ANALYSIS!A33:A37)) Call Rinterface.GetArray(pred_output$quant_two, Range(ASYM_MAX_ANALYSIS!I33:I37)) Call Rinterface.GetArray(sd_output$sd_one, Range(ASYM_MAX_ANALYSIS!B33:B37)) Call Rinterface.GetArray(sd_output$sd_two, Range(ASYM_MAX_ANALYSIS!J33:J37)) Call Rinterface.GetArray(sd_output$iqr_one, Range(ASYM_MAX_ANALYSIS!D33:D37)) Call Rinterface.GetArray(sd_output$iqr_two, Range(ASYM_MAX_ANALYSIS!L33:L37)) Call Rinterface.GetArray(pred_output$quant_one, Range(ASYM_MAX_ANALYSIS!A42:A46)) Call Rinterface.GetArray(pred_output$pred, Range(ASYM_MAX_ANALYSIS!C42:C46)) Call Rinterface.GetArray(pred_output$up_cb, Range(ASYM_MAX_ANALYSIS!I42:I46)) Call Rinterface.GetArray(pred_output$low_cb, Range(ASYM_MAX_ANALYSIS!K42:K46)) Call Rinterface.GetArray(sd_output$sd_ee[1], Range(ASYM_MAX_ANALYSIS!E50)) Call Rinterface.GetArray(pv_data$pool_sd, Range(ASYM_MAX_ANALYSIS!C55)) Call Rinterface.GetArray(pv_data$lin_sd_comb, Range(ASYM_MAX_ANALYSIS!D55)) Call Rinterface.GetArray(pv_data$const_sd_comb, Range(ASYM_MAX_ANALYSIS!I55)) Call Rinterface.GetArray(pv_data$CV_sd_comb, Range(ASYM_MAX_ANALYSIS!J55)) Call Rinterface.GetArray(pv_data$lin_sd_one, Range(ASYM_MAX_ANALYSIS!D58)) Call Rinterface.GetArray(pv_data$const_sd_one, Range(ASYM_MAX_ANALYSIS!I58)) Call Rinterface.GetArray(pv_data$CV_sd_one, Range(ASYM_MAX_ANALYSIS!J58)) Call Rinterface.GetArray(pv_data$lin_sd_two, Range(ASYM_MAX_ANALYSIS!D61)) Call Rinterface.GetArray(pv_data$const_sd_two, Range(ASYM_MAX_ANALYSIS!I61)) Call Rinterface.GetArray(pv_data$CV_sd_two, Range(ASYM_MAX_ANALYSIS!J61)) Call Rinterface.GetArray(pv_data$N_one, Range(ASYM_MAX_ANALYSIS!C64)) Call Rinterface.GetArray(pv_data$N_two, Range(ASYM_MAX_ANALYSIS!D64)) Call Rinterface.GetArray(pv_data$lin, Range(ASYM_MAX_ANALYSIS!I64)) Call Rinterface.GetArray(pv_data$FO, Range(ASYM_MAX_ANALYSIS!J64)) Call Rinterface.RRun(dev.off()) Call Rinterface.StopRServer Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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,
Re: [R] executing R batch files
Thank you, I appreciate your reply. I have managed to get Shell(c:\TEMP\Rbatch.bat) to work. What solved the problem was saving the Rbatch.bat file as type All files as opposed to as a text file. Why that worked, I have no idea. Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 Gabor Grothendieck ggrothendi...@gmail.com 02-Feb-2009 18:53 To joseph.g.bo...@gsk.com cc r-help@r-project.org Subject Re: [R] executing R batch files Without the actual VBA commands you are using we can't be sure but if you are using Shell then it requires an exe, not a bat file. Try cmd.exe /c RBatch.bat so that it has an exe file to execute. On Mon, Feb 2, 2009 at 6:42 PM, joseph.g.bo...@gsk.com wrote: The following command, issued from the DOS command prompt (running Windows XP), produces the intended result of a .csv file created by program.R: ?c:\program files\R\R-2.8.0\bin\Rterm.exe? --save c:\TEMP\program.R However, when I create a file called Rbatch.bat that contains exactly the line above, and try to execute it (by double clicking or via the Shell command in an Excel macro), nothing happens. Does anyone have an explanation, or any suggestions as to how to run an R program from within an Excel macro? (PS: I know about RExcel, can't quite get it to install correctly.) Much appreciated. Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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 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] executing R batch files
The following command, issued from the DOS command prompt (running Windows XP), produces the intended result of a .csv file created by program.R: ?c:\program files\R\R-2.8.0\bin\Rterm.exe? --save c:\TEMP\program.R However, when I create a file called Rbatch.bat that contains exactly the line above, and try to execute it (by double clicking or via the Shell command in an Excel macro), nothing happens. Does anyone have an explanation, or any suggestions as to how to run an R program from within an Excel macro? (PS: I know about RExcel, can't quite get it to install correctly.) Much appreciated. Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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] referring to calls in functions
The first program generates an error message and does not execute the regression of y on x. x-1:10; y-rnorm(10) + x; prac - function( model, wghts ){ lm(model, weights = wghts) } prac(model = y~x, wghts = rep(1, 10)) But the next program works: x-1:10; y-rnorm(10) + x; prac - function( y, x, wghts ){ lm(y~x, weights = wghts) } prac(y=y, x=x, wghts = rep(1, 10)) I would be grateful for an explanation of why the first program does not work. It seems to me like they should both give the same result. Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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] understanding recursive functions
Jeffrey and Jeff, Thank you for clearing this up. The problem was that I didn't read page 47 of the guide carefully. The introduction of the - operator on page 44 leaves me with the impression that - will create an assignment in the local environment THAT ALSO holds true for the next higher environment. Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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] understanding lexical scope
Thomas, Jeff, Mark, Antonio, Thank you for your answers. They have helped me clarify how R functions work. They work differently from SAS functions (which SAS calls macros.) If you know SAS, consider the following code: * %macro q(y); data one; outvar = y. + x.; output; call symputx(outvar, outvar, G); run; %mend; %macro w(x); %q(x.); %put outvar.; %mend; ** Then %w(2); will result in the value 4 being placed in the SAS log. To me, while the coding is quite awkward, the execution is logical. The variable x has been defined by the call to the macro w, so there is no problem when SAS encounters a reference to x in the macro q. But in the equivalent code in R, q - function(y) y +x; w - function(x) q(x); w(2); when R can't find the second argument of q in the local environment of the macro q, it doesn't look in the local environment of the macro w, it goes all the way back to the global environment, as you have all pointed out. So in my little model of how R functions work, when a function is called 1. R rewrites the body of the function, replacing all of the parameter names with the values given to them in the function call. 2. R then tries to execute the expressions. But R only remembers the assignment of values to parameter names during step 1. Thus in our example it has to go the global environment to find a value for x referenced in q. Is this right? Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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] understanding recursive functions
I'm trying to understand the use of recursive functions described on page 45 of An Introduction to R by the R core development team. A function is a list of expressions, which all get executed with only the last being assigned to a global variable, right? So if a function refers recursively to itself, it should simply start with the first expression and go from there. At least that is my understanding of why the example given on page 45 works. In light of the above, I would appreciate it if someone would understand why the following example does not work: q - function(x,h) {if (x 2) {x - x+1; return(q(x))} else return(x)} If x 1, this should add 1 to x and go back to the beginning of the if expression, and the final result should be 2. So q(0) should return 2. But it returns an error message. Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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.