[R] Help in error removal
David Winsemius
dwinsemius at comcast.net
Wed Jul 13 15:31:03 CEST 2011
On Jul 13, 2011, at 6:09 AM, Mitra, Sumona wrote:
> Dear all,
>
> Thank you so much for your help. I was able to get a script that ran
> and did what i wanted it to do. It was as follows:-
>
>
>> correlation <- function(a)
> + {
> + r <- matrix(nrow = dim(a)[1], ncol=dim(a)[1])
> + for(x in c(2:dim(a)[1]))
> + {
> + for(y in c(x:dim(a)[1]))
> + {
> + r[x,y] <- (cor.test(as.vector(as.matrix(a)[x,],
> mode="double"), as.vector(as.matrix(a)[y,], mode="double"))$p.value)
> + r[y,x] <- r[x,y]
> + }
> + }
> + return(r)
> + }
>
> Now I want to extend this to include all the possible correlations
> that cor.test can do.
You are constructing a technique that in the wrong hands will do very
bad statistics.
> One of the possible arguments of cor.test is method="method", where
> method can be pearson, spearman or kendall. To include this I
> modified my code in the following way:-
>
>> correlation <- function(a, b)
> + {
> + r <- matrix(nrow = dim(a)[1], ncol=dim(a)[1])
> + for(x in c(2:dim(a)[1]))
> + {
> + for(y in c(x:dim(a)[1]))
> + {
> + r[x,y] <- (cor.test(as.vector(as.matrix(a)[x,],
> mode="double"), as.vector(as.matrix(a)[y,], mode="double"),
> method="b")$p.value)
If you quote "b", then the interpreter will not substitute the value
of `b`.
> + r[y,x] <- r[x,y]
> + }
> + }
> + return(r)
> + }
>
> This when executed though, gives the following error:-
>
>> correlation(a, spearman)
> Error in match.arg(method) :
> 'arg' should be one of “pearson”, “kendall”, “spearman”
>
> Please help!
>
> Sumona
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list