[R] Mann Kendall Test for Trend

149 views
Skip to first unread message

ScottM

unread,
Sep 2, 2011, 11:35:16 AM9/2/11
to r-h...@r-project.org
Hi there,

I'm trying to apply the Mann Kendall test for trend analysis of a time
series. I have downloaded and installed the package Kendall and
subsequently loaded it into the software.

My time series is a .txt file with 2 columns - column 1 is the year (1985 -
2009) and column 2 is the corresponding entry variable.

According to the R guidelines, the call should be:

MannKendall(x) [whereby x is a data vector, usually a time series]

As such, I've loaded in my file 'data.txt' and then called on:

MannKendall(data), to which I get the following:

Error in Kendall(1:length(x), x) : length(x)<3

What do I need to do to get beyond this highly annoying error? I've tried
MannKendall(1:27(data), data), but then keep getting this:

Error in Kendall(1:length(x), x) : attempt to apply non-function

Any help greatly received!

S

--
View this message in context: http://r.789695.n4.nabble.com/Mann-Kendall-Test-for-Trend-tp3786392p3786392.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-h...@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. Michael Weylandt

unread,
Sep 2, 2011, 11:46:25 AM9/2/11
to ScottM, r-h...@r-project.org
I don't have the Kendall package at my fingers, but it seems like you have
some deeper trouble with R syntax if you are writing things like

MannKendall(1:27(data),data)

when you know that MannKendall only takes one argument.

Can you verify that your data object actually has a full set of data to it?
(use some combination of length(),nrow(),dput(),head(),tail() etc)

For a general tip, data() is a function to R so its not the best idea for an
object name. Outside chance that might be what's causing your problem.

Michael Weylandt

[[alternative HTML version deleted]]

ScottM

unread,
Sep 2, 2011, 12:00:05 PM9/2/11
to r-h...@r-project.org
Michael,

Cheers for the input - still learning "syntax" as I go - very new to the use of programming language and having to self teach as part of my PhD.

The input data was fine - it was the call on the R website which was confusing me - by defining the location of the actual data in the second column and calling "result <- MannKendall(filename[,2])", it worked without issue.

Cheers again though,

Scott McGrane MA (Hons), MRes
SAGES Theme 1 PhD Student
Northern Rivers Institute
St Mary's Building
University of Aberdeen

http://www.abdn.ac.uk/nri
________________________________________
From: R. Michael Weylandt <michael....@gmail.com> [via R] [ml-node+3786437-...@n4.nabble.com]
Sent: 02 September 2011 04:47 PM
To: Mcgrane, Scott
Subject: Re: Mann Kendall Test for Trend

I don't have the Kendall package at my fingers, but it seems like you have
some deeper trouble with R syntax if you are writing things like

MannKendall(1:27(data),data)

when you know that MannKendall only takes one argument.

Can you verify that your data object actually has a full set of data to it?
(use some combination of length(),nrow(),dput(),head(),tail() etc)

For a general tip, data() is a function to R so its not the best idea for an
object name. Outside chance that might be what's causing your problem.

Michael Weylandt

On Fri, Sep 2, 2011 at 11:35 AM, ScottM <[hidden email]</user/SendEmail.jtp?type=node&node=3786437&i=0>> wrote:

> Hi there,
>
> I'm trying to apply the Mann Kendall test for trend analysis of a time
> series. I have downloaded and installed the package Kendall and
> subsequently loaded it into the software.
>
> My time series is a .txt file with 2 columns - column 1 is the year (1985 -
> 2009) and column 2 is the corresponding entry variable.
>
> According to the R guidelines, the call should be:
>
> MannKendall(x) [whereby x is a data vector, usually a time series]
>
> As such, I've loaded in my file 'data.txt' and then called on:
>
> MannKendall(data), to which I get the following:
>
> Error in Kendall(1:length(x), x) : length(x)<3
>
> What do I need to do to get beyond this highly annoying error? I've tried
> MannKendall(1:27(data), data), but then keep getting this:
>
> Error in Kendall(1:length(x), x) : attempt to apply non-function
>
> Any help greatly received!
>
> S
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Mann-Kendall-Test-for-Trend-tp3786392p3786392.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________

> [hidden email]</user/SendEmail.jtp?type=node&node=3786437&i=1> 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]]

______________________________________________
[hidden email]</user/SendEmail.jtp?type=node&node=3786437&i=2> 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.


________________________________
If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/Mann-Kendall-Test-for-Trend-tp3786392p3786437.html
To unsubscribe from Mann Kendall Test for Trend, click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3786392&code=c2NvdHQubWNncmFuZUBhYmRuLmFjLnVrfDM3ODYzOTJ8OTM1MjEwNDY5>.


The University of Aberdeen is a charity registered in Scotland, No SC013683.


--
View this message in context: http://r.789695.n4.nabble.com/Mann-Kendall-Test-for-Trend-tp3786392p3786488.html


Sent from the R help mailing list archive at Nabble.com.

R. Michael Weylandt

unread,
Sep 2, 2011, 12:10:20 PM9/2/11
to ScottM, r-h...@r-project.org
I'd suggest that you look into using a time series class to organize your
data rather than just keeping levels and times next to each other. This will
also make it alot easier to work with your data in specific time-series sort
of ways.

I really like the xts class and you can get to it with something like the
following

install.package("xts")
library(xts)
x = read.table(HOWEVER YOU NEED TO READ THE DATA)
x = xts(x[,2],as.Date(x[,1], format = "%Y"))

The syntax to the last line is to construct an xts using the second column
of the data as the levels of the time series while the first reads the
years, coverts them to date objects (you supply the format, here its just a
year number)) and puts the thing together.

Then, I think you can just run MannKendall(x)

Hope this helps,

Michael Weylandt

PS -- There are all sorts of wonderful introductions to R for people with a
variety of programming backgrounds. If you want a recommendation, just say a
little more about any programming experience you may or may not have had and
I'm sure someone could recommend a few good ones.

Reply all
Reply to author
Forward
0 new messages