[R] Simple spectral analysis

2007-01-08 Thread Georg Hoermann
Hello world,

I am actually trying to transfer a lecture from Statistica to
R and I ran into problems with spectral analysis, I think I
just don't get it 8-(
(The posting from FFT, frequs, magnitudes, phases from 2005
did not enlighten me)

As a starter for the students I have a 10year data set of air 
temperature with daily values  and I try to
get a periodogram where the annual period (365 days) should be clearly
visible (in statistica I can get the frequencies and the period).
I tried the spectrum() and pgram() functions, but
did not find a way through... The final aim would be to
get the periodogram (and the residuals from the reassembled data set...)

Thanks and greetings,
Georg

The data set:

air = read.csv(http://www.hydrology.uni-kiel.de/~schorsch/air_temp.csv;)
airtemp = ts(T_air, start=c(1989,1), freq = 365)
plot(airtemp)


-- 
Georg Hoermann, Dep. of Hydrology, Ecology, Kiel University, Germany
+49/431/23761412, mo: +49/171/4995884, icq:348340729, skype: ghoermann

__
R-help@stat.math.ethz.ch 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] Simple spectral analysis

2007-01-08 Thread Georg Hoermann
Peter Dalgaard wrote:
 Earl F. Glynn wrote:
   
 The defaults for detrending and tapering could be involved. Putting, 
 e.g., detrend=F gives me a spectrum with substantially higher 
 low-frequency components.
 
 But what was the problem in the first place?
 
understanding how this things work in R compared to other packages 8-)

Thanks a lot for the help. I will post the script when its ready
(an introduction for our biology students to time series, just 8 hours)

Georg



-- 
Georg Hoermann, Dep. of Hydrology, Ecology, Kiel University, Germany
+49/431/23761412, mo: +49/171/4995884, icq:348340729, skype: ghoermann

__
R-help@stat.math.ethz.ch 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] Strange Colnames

2005-02-25 Thread Georg Hoermann
Hello world,
I am trying to create a matrix of lagged time series with the
following code fragment (I know that I can use acf-function...).
I want to set the variable/column name to something like
lag 1 etc. If I try to do it I get text like
lagtest.lagtest.lagtest.lag 1 where does this come from?
After a conversion to a data.frame it works as expected.
What did I miss?
Thanks and greetings,
Georg
==
 lagtest - as.ts(seq(1:100)) ;
 for (i in 1:4) {lagtest - cbind(lagtest,lag(ts_test,i)); 
colnames(lagtest)[i+1]- paste(lag,i)}
 colnames(lagtest)[1]-H_GW;
 colnames(lagtest)
[1] H_GW  lagtest.lagtest.lagtest.lag 1 
lagtest.lagtest.lag 2
[4] lagtest.lag 3 lag 4

# this works...
  t5 - as.data.frame(lagtest)
 for (i in 1:4) {names(t5)[i+1] - paste(var,i) }
 names(t5)
[1] H_GW  var 1 var 2 var 3 var 4

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Strange Colnames

2005-02-25 Thread Georg Hoermann
Miguel A. Arranz wrote:
You probably want to have a look at help(embed). It might be all you need.
embed wraps around (no NAs at begin and end of the dataset), this makes 
no sense in hydrology.

Gruss Georg
--
Georg Hoermann, Dep. of Hydrology, Ecology, Kiel University, Germany
Tel. 0431-880-1207, Home: 0451/477032, 0172/4315715, Penguin #189476
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Strange Colnames

2005-02-25 Thread Georg Hoermann
Gabor Grothendieck wrote:
Here is something you could try:
# define lags and their names
lags - 0:4
names(lags) - c(G_HW, paste(lag, 1:4))
# build mts
do.call(cbind, lapply(lags, lag, x = lagtest))
thank you for the solution,
I will try to understand it during the weekend 8-)
Now I tried to change the lag from the default value of 1 to -1,
but I apparently missed something:
 do.call(cbind, lapply(lags, function(x) lag(x,-1), x = lagtest))
Error in FUN(X[[1]], ...) : unused argument(s) ( ...)
where is the unused argument?
Thanks,
Georg
--
Georg Hoermann, Dep. of Hydrology, Ecology, Kiel University, Germany
Tel. 0431-880-1207, Home: 0451/477032, 0172/4315715, Penguin #189476
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Getting *types* of arguments?

2005-02-17 Thread Georg Hoermann
Hello world,

short question: is there a possibility to get a list of
arguments of a function *with* variable/parameter types?

formals() gives me the names of the parameters, but says
nothing about the parameter type it expects (I know I can always use the 
help function). 

I would like somthing like

$x: vector or data.frame...

Thanks in advance...

Georg


-- 
Georg Hoermann, Fachabteilung Wasserwirtschaft / Dep. Hydrology  
Ecosystem Research Center, Kiel University, Germany, Penguin #189476
Tel. 0431-880-1207, 0172/4315715, ICQ: 348340729, MSN: hlschorsch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Annual cumulative sums from time series

2005-02-10 Thread Georg Hoermann
Hello world,

I am actually transferring a course in data management for
students in biology, geography and agriculture 
from statistica to R - it works
surprisingly well. If anyone is interested in my scratch/notepad
(in German language), please see

www.hydrology.uni-kiel.de/~schorsch/statistik/statistik_datenauswertung.pdf

(pages 40-52)

The dataset is:

www.hydrology.uni-kiel.de/~schorsch/statistik/erle_stat.csv

It contains a 10 year dataset. So far for introduction, now
comes the problem:

we often need cumulative *annual* sums (sunshine, precipitation),
 i.e. the sum
must reset to 0 at the beginning of the year. I know
of cumsum(), but I do not now how to split the dataset automagically 
into annual pieces so I can cumsum() every year separately.
I have the strong hope that the solution is one of these
one-liners which leave the students with eyes wide open in surprise and 
makes them true believers in the power of the command-line 8-).

Thanks  Greetings
Georg


-- 
Georg Hoermann, Luebeck, Germany
Tel. 0451/47 70 32, 0172/431 57 15, Penguin #189476

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Annual cumulative sums from time series - SOLVED + questions

2005-02-10 Thread Georg Hoermann
Roger Bivand wrote:
On Thu, 10 Feb 2005, Georg Hoermann wrote:
Hello world,
based on the code of Roger I have now two solutions:
the first one (one line for the whole dataset)
- cut here --
erle - 
read.csv(url(http://www.hydrology.uni-kiel.de/~schorsch/statistik/erle_stat.csv;))
jahre - factor(substring(erle$DATUM, 7))
tpks1 - unlist(tapply(erle$Sonnen, jahre, cumsum))
plot(tpks1, type=l)

- cut here ---
The second one plots one line for each year:
 start - cut here 
# read data in from Internet
erle - 
read.csv(url(http://www.hydrology.uni-kiel.de/~schorsch/statistik/erle_stat.csv;))
# extract Year as a factor from variable DATUM
jahre - factor(substring(erle$DATUM, 7))
try1 - tapply(erle$Sonnen, jahre, cumsum)
# create colors for every year from rainbow color scheme
cols - rainbow(length(try1))
plot(x=c(1,366), y=c(0,1200), type=n, xlab=Days, ylab=Cumulative 
sunshine (h))
# draw the lines, one line for each year
for (i in 1:length(try1)) lines(1:length(try1[[i]]), try1[[i]], col=cols[i])

# ...and the legend
legend(c(0,100), c(400,1100), names(try1), col=cols, lwd=1, bty=n)
 end cut here -
For the second example, a mean sum for all years would also be a good 
idea...

Thanks for all solutions...
Merci  Gruss
Georg
--
Georg Hoermann, Dep. of Hydrology, Ecology, Kiel University, Germany
Tel. 0431-880-1207, icq - 348 340 729, 0172/4315715, Penguin #189476
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html