

I am analyzing trend using Mannkendall test for 31 independent sample, each sample have 34 years dataset. I supposed to find Kendall “tau” for each sample. The data is arranged in column wise (I attached the data).To find Kendall tau, I wrote R script as:
desta<read.csv("rainfall.csv", header=T, sep=",") require(Kendall) MK<function(y) { nc<ncol(y) MannKendalltau< numeric(nc) for(i in 2:nc){ MannKendalltau[i]<MannKendall(y[,i]) } MannKendalltau } MK(desta)
The displayed result showed both “tau” and “2sided pvalue”in unorganized way. But, I want only “tau” value that is presented in organized manner. Anyone can tell me how can I get orderly displayed “tau” value? here is my sample result: [[1]][1] 0
[[2]][1] 0.4352941attr(,"Csingle")[1] TRUE
[[3]][1] 0.5462185attr(,"Csingle")[1] TRUE
[[4]][1] 0.4218487attr(,"Csingle")[1] TRUE....Thank you for your guidance
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


This sounds like homework. Homework is discouraged on this list (but
you might get lucky).
Cheers,
Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 4677374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll
On Tue, Mar 31, 2015 at 9:08 AM, Desta Yoseph via Rhelp
< [hidden email]> wrote:
> I am analyzing trend using Mannkendall test for 31 independent sample, each sample have 34 years dataset. I supposed to find Kendall “tau” for each sample. The data is arranged in column wise (I attached the data).To find Kendall tau, I wrote R script as:
> desta<read.csv("rainfall.csv", header=T, sep=",") require(Kendall) MK<function(y) { nc<ncol(y) MannKendalltau< numeric(nc) for(i in 2:nc){ MannKendalltau[i]<MannKendall(y[,i]) } MannKendalltau } MK(desta)
> The displayed result showed both “tau” and “2sided pvalue”in unorganized way. But, I want only “tau” value that is presented in organized manner. Anyone can tell me how can I get orderly displayed “tau” value? here is my sample result: [[1]][1] 0
> [[2]][1] 0.4352941attr(,"Csingle")[1] TRUE
> [[3]][1] 0.5462185attr(,"Csingle")[1] TRUE
> [[4]][1] 0.4218487attr(,"Csingle")[1] TRUE....Thank you for your guidance
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


OK.
But always reply to the list (which I am ccing here) so that everyone
knows  and resubmit your OP in **PLAIN TEXT**, not html, as this is
a plain text list and html typically garbles everything.
Also, reading and following the posting guide (see end of this email)
generally improves your chance of getting useful help.
 Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 4677374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll
On Tue, Mar 31, 2015 at 9:24 AM, Desta Yoseph < [hidden email]> wrote:
> Dear Bert,
> It is not homework. Actually my real work is for 10,360 sample data. But if
> some one showed me for 31 sample dataset, i can manage for large sample
> data.
> hopefully this give you few hint why i really want someone help.
> cheers
>
>
>
> On Tuesday, March 31, 2015 6:14 PM, Bert Gunter < [hidden email]>
> wrote:
>
>
> This sounds like homework. Homework is discouraged on this list (but
> you might get lucky).
>
> Cheers,
> Bert
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
> (650) 4677374
>
> "Data is not information. Information is not knowledge. And knowledge
> is certainly not wisdom."
> Clifford Stoll
>
>
>
>
> On Tue, Mar 31, 2015 at 9:08 AM, Desta Yoseph via Rhelp
> < [hidden email]> wrote:
>> I am analyzing trend using Mannkendall test for 31 independent sample,
>> each sample have 34 years dataset. I supposed to find Kendall “tau” for
>> each sample. The data is arranged in column wise (I attached the data).To
>> find Kendall tau, I wrote R script as:
>> desta<read.csv("rainfall.csv", header=T, sep=",")
>> require(Kendall) MK<function(y) { nc<ncol(y)
>> MannKendalltau< numeric(nc) for(i in 2:nc){
>> MannKendalltau[i]<MannKendall(y[,i]) } MannKendalltau
>> } MK(desta)
>> The displayed result showed both “tau” and “2sided pvalue”in
>> unorganized way. But, I want only “tau” value that is presented in
>> organized manner. Anyone can tell me how can I get orderly displayed “tau”
>> value? here is my sample result: [[1]][1] 0
>> [[2]][1] 0.4352941attr(,"Csingle")[1] TRUE
>> [[3]][1] 0.5462185attr(,"Csingle")[1] TRUE
>> [[4]][1] 0.4218487attr(,"Csingle")[1] TRUE....Thank you for your guidance
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide
>> http://www.Rproject.org/postingguide.html>> and provide commented, minimal, selfcontained, reproducible code.
>
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


In reply to this post by R help mailing list2
> I am analyzing trend using Mannkendall test for 31 independent sample, each
> sample have 34 years dataset. I supposed to find Kendall “tau” for each
> sample. The data is arranged in column wise (I attached the data).To find
> Kendall tau, I wrote R script as:
> ...
> Anyone can tell me how can I get orderly displayed “tau” value?
Usually, in R, a hypothesis test returns an object, and you can extract an individual element of that object.
MannKendall seems to be no exception. Looking at the help page, a MannKendall test returns...
" A list with class Kendall.
tau Kendall’s tau statistic
sl twosided pvalue
S Kendall Score
D denominator, tau=S/D
varS variance of S"
To get just tau, say something like MannKendalltau[i]<MannKendall(y[,i])$tau
But your code is a bit of a mess....
MannKendalltau< numeric(nc) simply makes MannKendalltau a single integer equal to nc; that doesn't look sensible when the next thing you do is treat MannKendalltau as a vector. R's been kind to you and extended MannKendalltau when you tried to add things to later, nonexistent, elements, but it clearly wasn't the right thing to do. Look up ?numeric, and then look up ?vector for next time you want to set up an empty vector.
Second, since MannKendall(y[,i]) ) returns a list object of class Kendall, MannKendalltau[i]<MannKendall(y[,i]) assigns a whole object containing 5 values to each new element of your MannKendalltau. So your result is a list of lists.
Finally, you don’t need a loop at all. On a data frame, sapply would work nicely, so (although I've not tested it) something like
sapply(desta[,2:nc], 2, function(x) ManKendall(x)$tau)
ought to do the whole thing in one shot and package it nicely into a named vector while it's about it.
S Ellison
*******************************************************************
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If
you have received this message in error, please notify the sender
immediately via +44(0)20 8943 7000 or notify [hidden email]
and delete this message and any copies from your computer and network.
LGC Limited. Registered in England 2991879.
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> MannKendalltau< numeric(nc) simply makes MannKendalltau a single
> integer equal to nc; that doesn't look sensible when the next thing you
> do is treat MannKendalltau as a vector.
No, numeric(nc) makes a "numeric" (double precision) vector of length nc
filled with zeros.
Perhaps you were thinking of as.numeric(nc), which makes a numeric vector
of length one containing the value nc.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Thu, Apr 2, 2015 at 7:06 AM, S Ellison < [hidden email]> wrote:
> > I am analyzing trend using Mannkendall test for 31 independent
> sample, each
> > sample have 34 years dataset. I supposed to find Kendall “tau” for each
> > sample. The data is arranged in column wise (I attached the data).To
> find
> > Kendall tau, I wrote R script as:
> > ...
> > Anyone can tell me how can I get orderly displayed “tau” value?
>
> Usually, in R, a hypothesis test returns an object, and you can extract an
> individual element of that object.
>
> MannKendall seems to be no exception. Looking at the help page, a
> MannKendall test returns...
> " A list with class Kendall.
> tau Kendall’s tau statistic
> sl twosided pvalue
> S Kendall Score
> D denominator, tau=S/D
> varS variance of S"
>
> To get just tau, say something like
> MannKendalltau[i]<MannKendall(y[,i])$tau
>
> But your code is a bit of a mess....
> MannKendalltau< numeric(nc) simply makes MannKendalltau a single integer
> equal to nc; that doesn't look sensible when the next thing you do is treat
> MannKendalltau as a vector. R's been kind to you and extended
> MannKendalltau when you tried to add things to later, nonexistent,
> elements, but it clearly wasn't the right thing to do. Look up ?numeric,
> and then look up ?vector for next time you want to set up an empty vector.
>
> Second, since MannKendall(y[,i]) ) returns a list object of class Kendall,
> MannKendalltau[i]<MannKendall(y[,i]) assigns a whole object containing 5
> values to each new element of your MannKendalltau. So your result is a list
> of lists.
>
> Finally, you don’t need a loop at all. On a data frame, sapply would work
> nicely, so (although I've not tested it) something like
>
> sapply(desta[,2:nc], 2, function(x) ManKendall(x)$tau)
>
> ought to do the whole thing in one shot and package it nicely into a named
> vector while it's about it.
>
> S Ellison
>
>
> *******************************************************************
> This email and any attachments are confidential. Any u...{{dropped:17}}
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On Apr 2, 2015, at 7:06 AM, S Ellison wrote:
>> I am analyzing trend using Mannkendall test for 31 independent sample, each
>> sample have 34 years dataset. I supposed to find Kendall “tau” for each
>> sample. The data is arranged in column wise (I attached the data).To find
>> Kendall tau, I wrote R script as:
>> ...
>> Anyone can tell me how can I get orderly displayed “tau” value?
>
> Usually, in R, a hypothesis test returns an object, and you can extract an individual element of that object.
>
> MannKendall seems to be no exception. Looking at the help page, a MannKendall test returns...
> " A list with class Kendall.
> tau Kendall’s tau statistic
> sl twosided pvalue
> S Kendall Score
> D denominator, tau=S/D
> varS variance of S"
>
> To get just tau, say something like MannKendalltau[i]<MannKendall(y[,i])$tau
>
> But your code is a bit of a mess....
> MannKendalltau< numeric(nc) simply makes MannKendalltau a single integer equal to nc; that doesn't look sensible when the next thing you do is treat MannKendalltau as a vector. R's been kind to you and extended MannKendalltau when you tried to add things to later, nonexistent, elements, but it clearly wasn't the right thing to do. Look up ?numeric, and then look up ?vector for next time you want to set up an empty vector.
>
> Second, since MannKendall(y[,i]) ) returns a list object of class Kendall, MannKendalltau[i]<MannKendall(y[,i]) assigns a whole object containing 5 values to each new element of your MannKendalltau. So your result is a list of lists.
>
> Finally, you don’t need a loop at all. On a data frame, sapply would work nicely, so (although I've not tested it) something like
>
> sapply(desta[,2:nc], 2, function(x) ManKendall(x)$tau)
That looks more line an apply call. The second argument to sapply needs to be a function or function name.

David.
>
> ought to do the whole thing in one shot and package it nicely into a named vector while it's about it.
>
> S Ellison
>
>
> *******************************************************************
> This email and any attachments are confidential. Any u...{{dropped:19}}
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thank you for the explanation and comments. I managed to solve and your comments are helpfully! thanks once again,Desta
On Thursday, April 2, 2015 7:19 PM, David Winsemius < [hidden email]> wrote:
On Apr 2, 2015, at 7:06 AM, S Ellison wrote:
>> I am analyzing trend using Mannkendall test for 31 independent sample, each
>> sample have 34 years dataset. I supposed to find Kendall “tau” for each
>> sample. The data is arranged in column wise (I attached the data).To find
>> Kendall tau, I wrote R script as:
>> ...
>> Anyone can tell me how can I get orderly displayed “tau” value?
>
> Usually, in R, a hypothesis test returns an object, and you can extract an individual element of that object.
>
> MannKendall seems to be no exception. Looking at the help page, a MannKendall test returns...
> " A list with class Kendall.
> tau Kendall’s tau statistic
> sl twosided pvalue
> S Kendall Score
> D denominator, tau=S/D
> varS variance of S"
>
> To get just tau, say something like MannKendalltau[i]<MannKendall(y[,i])$tau
>
> But your code is a bit of a mess....
> MannKendalltau< numeric(nc) simply makes MannKendalltau a single integer equal to nc; that doesn't look sensible when the next thing you do is treat MannKendalltau as a vector. R's been kind to you and extended MannKendalltau when you tried to add things to later, nonexistent, elements, but it clearly wasn't the right thing to do. Look up ?numeric, and then look up ?vector for next time you want to set up an empty vector.
>
> Second, since MannKendall(y[,i]) ) returns a list object of class Kendall, MannKendalltau[i]<MannKendall(y[,i]) assigns a whole object containing 5 values to each new element of your MannKendalltau. So your result is a list of lists.
>
> Finally, you don’t need a loop at all. On a data frame, sapply would work nicely, so (although I've not tested it) something like
>
> sapply(desta[,2:nc], 2, function(x) ManKendall(x)$tau)
That looks more line an apply call. The second argument to sapply needs to be a function or function name.

David.
>
> ought to do the whole thing in one shot and package it nicely into a named vector while it's about it.
>
> S Ellison
>
>
> *******************************************************************
> This email and any attachments are confidential. Any u...{{dropped:12}}
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

