Re: [R] Jonckheere-Terpstra test using coin package?
Using coin ... answer provided by Prof. Hothorn. control - c(40, 35, 38, 43, 44, 41) rough - c(38, 40, 47, 44, 40, 42) accurate - c(48, 40, 45, 43, 46, 44) pieces - list(control, rough, accurate) n - c(6, 6, 6) grp - as.ordered(factor(rep(1:length(n),n))) library(coin) library(multcomp) (y - unlist(pieces)) k - length(pieces) (x - as.ordered(factor(rep(1:k,n ### look at K. The second line just sums up. ff - function(x) { K - contrMat(table(x), Tukey)[,x] as.vector(rep(1, nrow(K)) %*%K) } independence_test(y ~ x, ytrafo = rank, xtrafo = function(data) trafo(data, factor_trafo = ff), alternative=greater, distribution=asymptotic) independence_test(y ~ x, ytrafo = rank, xtrafo = function(data) trafo(data, factor_trafo = ff), alternative=greater, distribution=approximate(B=50)) On Wed, Apr 21, 2010 at 8:23 PM, Dale Steele dale.w.ste...@gmail.com wrote: Is it possible to implement the Jonckheere-Terpstra test for ordered alternatives using the coin package: Conditional Inference Procedures in a Permutation Test Framework? I found jonckheere.test{clinfun}, but it uses a normal approximation when ties are present in the data. To make this concrete, I've include a small dataset. Thanks. --Dale Hollander and Wolfe, 1999 Table 6.6, pg 205 control - c(40, 35, 38, 43, 44, 41) rough - c(38, 40, 47, 44, 40, 42) accurate - c(48, 40, 45, 43, 46, 44) pieces - list(control, rough, accurate) n - c(6, 6, 6) grp - as.ordered(factor(rep(1:length(n),n))) library(clinfun) jonckheere.test(unlist(pieces), grp, alternative=increasing) Output below ... jonckheere.test(unlist(pieces), grp, alternative=increasing) Jonckheere-Terpstra test data: JT = 79, p-value = 0.02163 alternative hypothesis: increasing Warning message: In jonckheere.test(unlist(pieces), grp, alternative = increasing) : TIES: p-value based on normal approximation __ 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] Jonckheere-Terpstra test using coin package?
Is it possible to implement the Jonckheere-Terpstra test for ordered alternatives using the coin package: Conditional Inference Procedures in a Permutation Test Framework? I found jonckheere.test{clinfun}, but it uses a normal approximation when ties are present in the data. To make this concrete, I've include a small dataset. Thanks. --Dale Hollander and Wolfe, 1999 Table 6.6, pg 205 control - c(40, 35, 38, 43, 44, 41) rough - c(38, 40, 47, 44, 40, 42) accurate - c(48, 40, 45, 43, 46, 44) pieces - list(control, rough, accurate) n - c(6, 6, 6) grp - as.ordered(factor(rep(1:length(n),n))) library(clinfun) jonckheere.test(unlist(pieces), grp, alternative=increasing) Output below ... jonckheere.test(unlist(pieces), grp, alternative=increasing) Jonckheere-Terpstra test data: JT = 79, p-value = 0.02163 alternative hypothesis: increasing Warning message: In jonckheere.test(unlist(pieces), grp, alternative = increasing) : TIES: p-value based on normal approximation __ 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] possible arrangements of across sample ties for runs test
I'm trying to implement the two-sample Wald-Wolfowitz runs test. Daniel (1990) suggests a method to deal with ties across samples. His suggestion is to prepare ordered arrangements, one resulting in the fewest number of runs, and one resulting in the largest number of runs. Then take the mean of these. The code below counts 9 runs for my example data where '60' is tied across samples. X - c(58, 62, 55, 60, 60, 67) n1 - length(X) Y - c(60, 59, 72, 73, 56, 53, 50, 50) n2 - length(Y) data - c(X, Y) names(data) - c(rep(X, n1), rep(Y, n2)) data - sort(data) runs - rle(names(data)) r - length(runs$lengths) r Y Y Y X Y X Y X X Y X X Y Y 50 50 53 55 56 58 59 60 60 60 62 67 72 73 -- r = 9 runs The other possible orderings are: Y Y Y X Y X Y X Y X X X Y Y -- 9 runs 50 50 53 55 56 58 59 60 60 60 62 67 72 73 Y Y Y X Y X Y Y X X X X Y Y -- 7 runs 50 50 53 55 56 58 59 60 60 60 62 67 72 73 How to I generate the other possible orderings? Thus, far, I've found a day to identify cross sample duplicates... # find the ties across samples dd - data[duplicated(data)] #find all duplicates idd - dd %in% X dd %in% Y #determine found in both X and Y duplicates - dd[idd] Thanks! --Dale [[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] behavior of seq_along
I'm trying to understand the behavior of seq_along in the following example: x - 1:5; sum(x) y - 6:10; sum(y) data - c(x,y) S - sum( data[seq_along(x)] ) S T - sum( data[seq_along(y)] ) T Why is T != sum(y) ? __ 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] How to use a 'hidden' function directly?
I would like to be able to use two functions; qansari and pansari which are found in the function ansari.test. How can I evaluate these functions independently? Thanks. --Dale For example, when I load the function ... qansari - function(p, m, n) { .C(R_qansari, as.integer(length(p)), q = as.double(p), as.integer(m), as.integer(n))$q } and attempt to evaluate ... qansari( 0.025, 5, 5) Error in qansari(0.025, 5, 5) : object 'R_qansari' not found methods(ansari.test) stats:::ansari.test.default the two functions that are part of ansari.test.default: qansari - function(p, m, n) { .C(R_qansari, as.integer(length(p)), q = as.double(p), as.integer(m), as.integer(n))$q } pansari - function(q, m, n) { .C(R_pansari, as.integer(length(q)), p = as.double(q), as.integer(m), as.integer(n))$p } __ 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] How to use a 'hidden' function directly?
Thanks, when I modify the function as I think you suggest, I get the following error: qansari - function(p, m, n) { .C(R_qansari, as.integer(length(p)), q = as.double(p), as.integer(m), as.integer(n))$q } qansari( 0.025, 5, 5) Error in .C(R_qansari, as.integer(length(p)), q = as.double(p), as.integer(m), : C symbol name R_qansari not in load table --Dale On Wed, Feb 24, 2010 at 8:47 PM, Sharpie ch...@sharpsteen.net wrote: Dale Steele wrote: I would like to be able to use two functions; qansari and pansari which are found in the function ansari.test. How can I evaluate these functions independently? Thanks. --Dale For example, when I load the function ... qansari - function(p, m, n) { .C(R_qansari, as.integer(length(p)), q = as.double(p), as.integer(m), as.integer(n))$q } and attempt to evaluate ... qansari( 0.025, 5, 5) Error in qansari(0.025, 5, 5) : object 'R_qansari' not found If R_qansari is the name of a compiled C subroutine you are trying to execute, then it needs to be passed to .C as a quoted string: .C( R_qansari , as.integer(length(p)), q = as.double(p), as.integer(m), as.integer(n))$q Otherwise R, as usual, is looking for a *variable* named R_qansari that it assumes holds a string that will tell it which C routine to call. It does not find such a variable and gives the error message shown above. -Charlie Dale Steele wrote: methods(ansari.test) stats:::ansari.test.default the two functions that are part of ansari.test.default: qansari - function(p, m, n) { .C(R_qansari, as.integer(length(p)), q = as.double(p), as.integer(m), as.integer(n))$q } pansari - function(q, m, n) { .C(R_pansari, as.integer(length(q)), p = as.double(q), as.integer(m), as.integer(n))$p } -- View this message in context: http://n4.nabble.com/How-to-use-a-hidden-function-directly-tp1568392p1568401.html Sent from the R help mailing list archive at Nabble.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-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] Code find exact distribution for runs test?
Wow! Your reply amply demonstrates the power of understanding the math (or finding someone who does) before turning on the computer. One last R question...how could I efficiently enumerate all distinguishable permutations of a vector of signs? vect - c( -1, -1, 1, 1, 1) permn(vect) #length: factorial(length(vect)) #length: choose(n, n1) Best Regards. --Dale On Thu, Feb 11, 2010 at 10:04 PM, Greg Snow greg.s...@imail.org wrote: Try this: druns2 - function(x, n1, n2) { if( x %% 2 ) { # odd x choose( n1 - 1, n1 - (x+1)/2 ) * choose( n2 - 1, n2 - (x-1)/2 ) / choose( n1+n2, n1 ) + choose( n2 - 1, n2 - (x+1)/2 ) * choose( n1 - 1, n1 - (x-1)/2 ) / choose( n1+n2, n2 ) } else { # even x choose( n1 - 1, n1 - x/2 ) * choose( n2 - 1, n2 - x/2 ) / choose( n1 + n2, n1 ) + choose( n2 - 1, n2 - x/2 ) * choose( n1 - 1, n1 - x/2 ) / choose( n1 + n2, n2 ) } } exp.2 - sapply( 2:7, druns2, n1=3, n2=4 ) exp.2 - exp.r/factorial(7) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: Dale Steele [mailto:dale.w.ste...@gmail.com] Sent: Thursday, February 11, 2010 5:28 PM To: Greg Snow Cc: R-help@r-project.org Subject: Re: [R] Code find exact distribution for runs test? Thanks for this! My original query was probably unclear. I think you have answered a different, possibly more interesting question. My goal was to find an exact distribution of a total number of runs R in samples of two types of size (n1, n2) under the null hypothesis of randomness. The horribly inefficient code below generates results which match Table 10 in Wackerly, Mendehall and Scheaffer for the distribution of the total number of runs R in samples of size (n1, n2); P(R = r), under the null hypothesis of randomness. Horribly inefficient because couldn't figure out how to generate only the distinguishable permutations of my sample vector. Hope this brute force approach illustrates what I am after. nruns - function(x) { signs - sign(x) runs - rle(signs) r - length(runs$lengths) return(r) } library(combinat) # for example (n1=3, n2=4) n1 - 3; n2 - 4; n - n1+n2 vect - rep( c(-1,1), c(3,4)) vect # ! 'nruns(vect)' generates factorial(7) permutations, only choose(7,3) are distinguishable exp.r - table(unlist(permn(vect, nruns ))) cumsum(dist/factorial(7)) # Result agrees with Table 10, pg 814 (n1=3, n2=4) #in Wackerly, Mendenhall and Scheaffer, 2002, presumably done using # exact calculations. Thanks. --Dale On Thu, Feb 11, 2010 at 6:08 PM, Greg Snow greg.s...@imail.org wrote: OK, I think I have it worked out for both cases: library(vcd) druns - function(x, n) { # x runs in n data points, not vectorized # based on sample median if( n%%2 ) stop('n must be even') if( x %% 2 ) { # odd x choose( n/2 - 1, n/2-(x+1)/2 ) * choose( n/2 - 1, n/2- (x-1)/2 )/ choose(n,n/2) * 2 } else { # even x choose( n/2 - 1, n/2-x/2 ) * choose( n/2 - 1, n/2-x/2 )/ choose(n,n/2) * 2 } } ## population median out1 - replicate( 10, {x - rnorm(10); length(rle(sign(x))$lengths) } ) rootogram( table(out1), dbinom(0:9, size=9, prob=0.5)*10 ) chisq.test( table(out1), p=dbinom(0:9, size=9, prob=0.5) ) ## sample median out2 - replicate( 10, {x - rnorm(10); x - x - median(x); length(rle(sign(x))$lengths) } ) fit - sapply( 2:10, druns, n=10 ) rootogram( table(out2), fit * 10 ) chisq.test( table(out2), p=fit ) The tests only fail to prove me wrong, not a firm proof that I am correct. But given the simulation size I am at least pretty close. I can see why people worked out approximations before we had good computers, I would not want to calculate the above by hand. Enjoy, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Greg Snow Sent: Thursday, February 11, 2010 12:19 PM To: Dale Steele; R-help@r-project.org Subject: Re: [R] Code find exact distribution for runs test? I am not an expert in this area, but here are some thoughts that may get you started towards an answer. First, there are 2 ways (possibly more) that can lead to the data for a runs test that lead to different theoretical distributions: 1. We have a true or hypothesized value of the median that we subtracted from the data, therefore each value has 50% probability of being positive/negative and all are independent of each other (assuming
Re: [R] Code find exact distribution for runs test?
Thanks for this! My original query was probably unclear. I think you have answered a different, possibly more interesting question. My goal was to find an exact distribution of a total number of runs R in samples of two types of size (n1, n2) under the null hypothesis of randomness. The horribly inefficient code below generates results which match Table 10 in Wackerly, Mendehall and Scheaffer for the distribution of the total number of runs R in samples of size (n1, n2); P(R = r), under the null hypothesis of randomness. Horribly inefficient because couldn't figure out how to generate only the distinguishable permutations of my sample vector. Hope this brute force approach illustrates what I am after. nruns - function(x) { signs - sign(x) runs - rle(signs) r - length(runs$lengths) return(r) } library(combinat) # for example (n1=3, n2=4) n1 - 3; n2 - 4; n - n1+n2 vect - rep( c(-1,1), c(3,4)) vect # ! 'nruns(vect)' generates factorial(7) permutations, only choose(7,3) are distinguishable exp.r - table(unlist(permn(vect, nruns ))) cumsum(dist/factorial(7)) # Result agrees with Table 10, pg 814 (n1=3, n2=4) #in Wackerly, Mendenhall and Scheaffer, 2002, presumably done using # exact calculations. Thanks. --Dale On Thu, Feb 11, 2010 at 6:08 PM, Greg Snow greg.s...@imail.org wrote: OK, I think I have it worked out for both cases: library(vcd) druns - function(x, n) { # x runs in n data points, not vectorized # based on sample median if( n%%2 ) stop('n must be even') if( x %% 2 ) { # odd x choose( n/2 - 1, n/2-(x+1)/2 ) * choose( n/2 - 1, n/2-(x-1)/2 )/ choose(n,n/2) * 2 } else { # even x choose( n/2 - 1, n/2-x/2 ) * choose( n/2 - 1, n/2-x/2 )/ choose(n,n/2) * 2 } } ## population median out1 - replicate( 10, {x - rnorm(10); length(rle(sign(x))$lengths) } ) rootogram( table(out1), dbinom(0:9, size=9, prob=0.5)*10 ) chisq.test( table(out1), p=dbinom(0:9, size=9, prob=0.5) ) ## sample median out2 - replicate( 10, {x - rnorm(10); x - x - median(x); length(rle(sign(x))$lengths) } ) fit - sapply( 2:10, druns, n=10 ) rootogram( table(out2), fit * 10 ) chisq.test( table(out2), p=fit ) The tests only fail to prove me wrong, not a firm proof that I am correct. But given the simulation size I am at least pretty close. I can see why people worked out approximations before we had good computers, I would not want to calculate the above by hand. Enjoy, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Greg Snow Sent: Thursday, February 11, 2010 12:19 PM To: Dale Steele; R-help@r-project.org Subject: Re: [R] Code find exact distribution for runs test? I am not an expert in this area, but here are some thoughts that may get you started towards an answer. First, there are 2 ways (possibly more) that can lead to the data for a runs test that lead to different theoretical distributions: 1. We have a true or hypothesized value of the median that we subtracted from the data, therefore each value has 50% probability of being positive/negative and all are independent of each other (assuming being exactly equal to the median is impossible or discarded). 2. We have subtracted the sample median from each sample value (and discarded any 0's) leaving us with exactly half positive and half negative and not having independence. In case 1, the 1st observation will always start a run. The second observation has a 50% chance of being the same sign (F) or different sign (S), with the probability being 0.5 for each new observation and them all being independent (under assumption of random selections from population with known/hypothesized median) and the number of runs equaling the number of S's, this looks like a binomial to me (with some '-1's inserted in appropriate places. In case 2, this looks like a hypergeometric distribution, there would be n!/((n/2)!(n/2)!) possible permutations, just need to compute how many of those permutations result in x runs to get the probability. There is probably a way to think about this in terms of balls and urns, but I have not worked that out yet. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Dale Steele Sent: Wednesday, February 10, 2010 6:16 PM To: R-help@r-project.org Subject: [R] Code find exact distribution for runs test? I've been attempting to understand the one-sample run test
[R] Code find exact distribution for runs test?
I've been attempting to understand the one-sample run test for randomness. I've found run.test{tseries} and run.test{lawstat}. Both use a large sample approximation for distribution of the total number of runs in a sample of n1 observations of one type and n2 observations of another type. I've been unable to find R code to generate the exact distribution and would like to see how this could be done (not homework). For example, given the data: dtemp - c(12, 13, 12, 11, 5, 2, -1, 2, -1, 3, 2, -6, -7, -7, -12, -9, 6, 7, 10, 6, 1, 1, 3, 7, -2, -6, -6, -5, -2, -1) The Monte Carlo permutation approach seems to get me part way. # calculate the number of runs in the data vector nruns - function(x) { signs - sign(x) runs - rle(signs) r - length(runs$lengths) return(r) } MC.runs - function(x, nperm) { RUNS - numeric(nperm) for (i in 1:nperm) { RUNS[i] - nruns(sample(x)) } cdf - cumsum(table(RUNS))/nperm return(list(RUNS=RUNS, cdf=cdf, nperm=nperm)) } MC.runs(dtemp, 10) Thanks. --Dale __ 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] Wilcoxon signed-ranks test using package coin ?
Given the following data, and hypothesized median M.0 I've found a method to implement the Wilcoxon signed-rank test. Data: (with one zero difference and tied ranks) x - c(136, 103, 91, 122, 96, 145, 140, 138, 126, 120, 99, 125, 91,142, 119, 137) M.0 - 119 library(exactRankTests) Package ‘exactRankTests’ is no longer under development. Please consider using package ‘coin’ instead. wilcox.exact(x, mu=M.0) Exact Wilcoxon signed rank test data: x V = 65.5, p-value = 0.771 alternative hypothesis: true mu is not equal to 119 I've been unable to implement this test using library(coin) - is this possible? Thanks. --Dale __ 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] How to Reshuffle a distance object
I would like to randomly shuffle a distance object, such as the one created by ade4{dist.binary} below. My first attempt, using sample(jc.dist) creates a shuffled vector, losing the lower triangular structure of the distance object. How can I Ishuffle the lower triangular part of a distance matrix without losing the structure? Thanks. --Dale x1 - c(rep(0,4),1) x2 - c(rep(0,2),rep(1,3)) x3 - c(rep(1,3), rep(0,2)) X - rbind(x1,x2,x3) X X - as.data.frame(X) library(ade4) jc.dist - dist.binary(X, method=1) sample(jc.dist) __ 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] code to find all distinct subsets of size r from a set of size n
I'm doing a permutation test and need to efficiently generate all distinct subsets of size r from a set of size n. P 138 of MASS (4th ed) notes that The code to generate this efficiently is in the scripts. I was unable to find this code on quick inspection of the \library\MASS\scripts file for Chapter 5 and 'subsets' is not a function in MASS. I did find this problem is discussed in RNews, Programmer's Niche 1(1):27 - 30 and RNews, 1(2):29-31. Is there function in 'base' R or other package to do this? Thanks. --Dale __ 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] Efficent way to create an nxn upper triangular matrix of one's
The code below create an nxn upper triangular matrix of one's. I'm stuck on finding a more efficient vectorized way - Thanks. --Dale n - 9 data - matrix(data=NA, nrow=n, ncol=n) data for (i in 1:n) { data[,i] - c(rep(1,i), rep(0,n-i)) } data __ 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] Finding the distance between ordered integers
I'm stuck on how best to of find the distance between ordered integers (presented below as a birthday problem). Given the vector x, how do I most efficiently generate the vector x[i+1] - x[i]? Thanks. --Dale For example... set.seed(555) x - sample(1:365, 10, replace=TRUE) x - sort(x) x x[i+1]-x[i] ------ 14 14 0 75 61 136 61 197 61 236 39 253 17 310 57 323 13 355 32 __ 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] Beautify R scripts in microsoft word
Open script in Tinn-R, select script to copy. Then use menu Edit:Copy formatted (to export) -- RTF Paste into MS word. --Dale On Sat, Sep 13, 2008 at 1:30 PM, Daren Tan [EMAIL PROTECTED] wrote: I am generating a report containing several R scripts in the appendix. Is there any way to beautify the R source codes in microsoft word, similar to what we see in tinn-R ? Thanks _ [[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] Configuring emacs/ess on Ubuntu
$ sudo apt-get install Installs installs ESS version 5.3.0. Is there a repository for more recent version? Thanks. --Dale On Sun, May 25, 2008 at 11:24 AM, Roland Rau [EMAIL PROTECTED] wrote: Hi Wade, Wade Wall wrote: Hi all, I don't know if this is the proper place to ask this, but I am trying to configure emacs/ess on Ubuntu 8.04 to run the way described for ESS and I think the easiest way to install emacs/ess on Ubuntu 8.04 is via the repositories. Simply use your favorite package manager (I use synaptic) and choose the ess package. If Emacs hasn't been installed yet, it will do so automatically. I hope this helps, Roland __ 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] Finding Interaction and main effects contrasts for two-wayANOVA
Thanks to those who have replied to my original query. However, I'm still confused on how obtain estimates, standard error and F-tests for main effect and interaction contrasts which agree with the SAS code with output appended below. for example, ## Given the dataset (from Montgomery) twoway - read.table(http://dsteele.veryspeedy.net/sta501/twoway.txt;, col.names=c('material', 'temp','voltage'),colClasses=c('factor', 'factor', 'numeric')) ## the model fit - aov(voltage ~ material*temp, data=twoway) material.means - tapply(twoway$voltage, twoway$material, mean) temp.means - tapply(twoway$voltage, twoway$temp, mean) cell.means - tapply(twoway$voltage, twoway[,1:2], mean) Contrasts of Interest cell.means[2,1] - cell.means[2,2] - cell.means[3,1] + cell.means[3,2] [1] 37.75 material.means[1] - material.means[2] 1 -25.16667 temp.means[1] - temp.means[3] 50 80.7 I expected the following code to provide the estimates above for (material 1 - material 2) and (temp1 - temp3), but get unexpected results... library(gmodels) fit.contrast(fit, material, rbind((1 - 2) =c(1, -1, 0) )) Estimate Std. Error t value Pr(|t|) material(1 - 2) -21 18.37407 -1.142915 0.2631074 fit.contrast(fit, temp, rbind(50 - 80 =c(1, 0, -1) )) Estimate Std. Error t value Pr(|t|) temp50 - 8077.25 18.37407 4.204294 0.0002572756 Thanks. --Dale /* SAS code */ proc glm data=twoway; class material temp; model voltage = material temp material*temp; contrast '21-22-31+32' material*temp 0 0 0 1 -1 0 -1 1 0; estimate '21-22-31+32' material*temp 0 0 0 1 -1 0 -1 1 0; contrast 'material1-material2' material 1 -1 0; estimate 'material1-material2' material 1 -1 0; contrast 'temp50 - temp80' temp 1 0 -1; estimate 'temp50 - temp80' temp 1 0 -1; run; SAS output Contrast DFContrast SSMean Square F Value Pr F 21-22-31+32 1 1425.06250 1425.06250 2.11 0.1578 material1-material2 1 3800.16667 3800.16667 5.63 0.0251 temp50 - temp80 139042.739042.7 57.82 .0001 Standard Parameter Estimate Errort ValuePr |t| 21-22-31+32 37.750 25.9848603 1.45 0.1578 material1-material2 -25.167 10.6082748 -2.37 0.0251 temp50 - temp80 80.667 10.6082748 7.60 .0001 On Sat, Mar 8, 2008 at 11:02 AM, Gregory Warnes [EMAIL PROTECTED] wrote: Dale, You might find it fruitful to look at the help pages for fit.contrast () and estimble() functions in the gmodels package, and the contrast () functions in the Hmisc package. -Greg On Mar 7, 2008, at 4:20PM , Thompson, David ((MNR)) wrote: Dale, Other than the first SAS contrast, does the following demonstrate what your asking for? summary(twoway) material temp voltage 1:12 50:12 Min. : 20 2:12 65:12 1st Qu.: 70 3:12 80:12 Median :108 Mean :106 3rd Qu.:142 Max. :188 contrasts(twoway$material) 2 3 1 0 0 2 1 0 3 0 1 contrasts(twoway$temp) 65 80 50 0 0 65 1 0 80 0 1 fit - aov(voltage ~ material*temp, data=twoway) summary.aov(fit) Df Sum Sq Mean Sq F value Pr(F) material 2 1068453427.91 0.0020 ** temp 2 39119 19559 28.97 1.9e-07 *** material:temp 4 961424033.56 0.0186 * Residuals 27 18231 675 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 # setting (partial) contrasts contrasts(twoway$material) - c(1,-1,0) # ignoring the second available df contrasts(twoway$temp) - c(0,1,-1) # ignoring the second available df contrasts(twoway$material) [,1] [,2] 11 -0.41 2 -1 -0.41 30 0.82 contrasts(twoway$temp) [,1] [,2] 500 -0.82 651 0.41 80 -1 0.41 summary.aov(fit, split=list(material=list('m1-m2'=1), temp=list ('t50 - t80'=1))) Df Sum Sq Mean Sq F value Pr(F) material 2 1068453427.91 0.00198 ** material: m1-m2 1 380038005.63 0.02506 * temp 2 39119 19559 28.97 1.9e-07 *** temp: t50 - t80 1 11310 11310 16.75 0.00035 *** material:temp 4 961424033.56 0.01861 * material:temp: m1-m2.t50 - t80 1 497049707.36 0.01146 * Residuals27 18231 675 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 # other examples of setting contrasts # compare m1 vs m2 and m2 vs m3 contrasts(twoway$material) - matrix(c(1,-1,0,1,1,-2),
[R] Finding Interaction and main effects contrasts for two-way ANOVA
I've tried without success to calculate interaction and main effects contrasts using R. I've found the functions C(), contrasts(), se.contrasts() and fit.contrasts() in package gmodels. Given the url for a small dataset and the two-way anova model below, I'd like to reproduce the results from appended SAS code. Thanks. --Dale. ## the dataset (from Montgomery) twoway - read.table(http://dsteele.veryspeedy.net/sta501/twoway.txt;, col.names=c('material', 'temp','voltage'),colClasses=c('factor', 'factor', 'numeric')) ## the model fit - aov(voltage ~ material*temp, data=twoway) /* SAS code */ proc glm data=twoway; class material temp; model voltage = material temp material*temp; contrast '21-22-31+32' material*temp 0 0 0 1 -1 0 -1 1 0; estimate '21-22-31+32' material*temp 0 0 0 1 -1 0 -1 1 0; contrast 'material1-material2' material 1 -1 0; estimate 'material1-material2' material 1 -1 0; contrast 'temp50 - temp80' temp 1 0 -1; estimate 'temp50 - temp80' temp 1 0 -1; run; __ 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] help.start() on linux (fedora 8) when firefox alreading running - a way to open a new tab?
Thanks. I found the issue. I was starting R in a terminal with the command 'sudo R', help.start() was not able to communicate Firefox when already running. Works fine when R is started as user. --Dale On Mon, Mar 3, 2008 at 3:09 PM, Marc Schwartz [EMAIL PROTECTED] wrote: Patrick Connolly wrote: On Sun, 02-Mar-2008 at 05:32PM -0500, Dale Steele wrote: | Using linux fedora 8 (x86_64) I get the following when firefox is | already running. Is there a way to adjust settings in either R or | firefox to open a new tab when help.start() is invoked? Thanks. Using FC6, it works as it says, except that I don't have to switch to the firefox window: it does that in about 1 second (and in a new tab). That's if I use firefox as the browser: if I use konqueror, it DOES start a new instance contrary to the message. My guess is that it has to do with your window manager's settings. There are many permutations that could be different from mine. I don't think it's an R setting. | --Dale | | help.start() | Making links in per-session dir ... | If '/usr/bin/firefox' is already running, it is *not* restarted, and | you must switch to its window. | Otherwise, be patient ... In the Firefox menus go to: Edit - Preferences - Tabs On that page, under New pages should be opened in: Select 'a new tab' If you are getting a new instance of Firefox, you likely have 'a new window' selected rather than 'a new tab'. The above works in FF version 2 and 3 beta on F8. HTH, Marc Schwartz __ 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.start() on linux (fedora 8) when firefox alreading running - a way to open a new tab?
Using linux fedora 8 (x86_64) I get the following when firefox is already running. Is there a way to adjust settings in either R or firefox to open a new tab when help.start() is invoked? Thanks. --Dale help.start() Making links in per-session dir ... If '/usr/bin/firefox' is already running, it is *not* restarted, and you must switch to its window. Otherwise, be patient ... __ 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] problem applying a conditional formula to each element of a matrix
I'm applying a function (Cov.f) defined below to each element of a distance matrix. When I run the code below, I get a warning message (below) and elements of returned matrix [2,3] and [3,2] are not zero as I would expect. Clearly, there is an error... What am I doing wrong? Thanks. --Dale Warning message: In if (h = phi) { : the condition has length 1 and only the first element will be used # function Cov.f - function(h, sigmasq, phi) { if (h = phi) {Cij - sigmasq * (1 - ( 1.5 * (h/phi) - 0.5 * (h/phi)^3)) } else if (h phi) {Cij - 0} return(Cij) } x.coord - c(5.7, 6.7, 9.8) y.coord - c(42.7, 10.2, 77.4) coords - cbind(x.coord, y.coord) distance.matrix - as.matrix(dist(coords, method=euclidean)) distance.matrix Cov.f(distance.matrix, 3.9, 58.1) __ 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] Function to find boundary of an irregular sample?
Given a set of coordinates that form an irregular sampling area, is there an R function to determine boundary points (coordinates defining the limits of the area), either with or without user interaction ? # for example, given the following irregular sampling area, how could I define the boundary polygon? library(SemiPar) data(scallop) plot(scallop$longitude, scallop$latitude) Thanks. --Dale __ 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] reason for error in small function?
Running the function below, tested using the cardiff dataset from splancs generates the following error. What changes do I need to make to get the function to work? Thanks. --Dale gen.rpoints(events, poly, 99) rpoints Error: object rpoints not found # test spatial data library(splancs) data(cardiff) attach(cardiff) str(cardiff) events - as.points(x,y) ### non-working function gen.rpoints - function(events, poly, nsim){ rpoints - array(0, dim=c(nrow(events),2,nsim)) for (i in 1:nsim) { rpoints[, ,i] - csr(poly, nrow(events)) } } __ 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.