jeroen clarysse
2004-Jun-18 09:23 UTC
[R] [Q] Newbie (continued.. at least I got R running allready :-)
Hi all a week ago, I posted a newbie question in data smoothing & maximum-extraction with R. I got quite a lot of response, but I'm still kinda stuck with it... I'll restate the problem : i got a datafile with 2400 measuerements (every 250msec) of a CO2 measurement device, capturing the breath of a subject. I uploaded such a sample here : http://www.psy.kuleuven.ac.be/leerpsy/data.csv now I wish to figure out where each breath expiration ceiling takes place , as shown on this graph : http://www.psy.kuleuven.ac.be/leerpsy/graph.bmp I'm kinda stuck on how to get this running in R. I really hope someone can help me out. If you guys can get me running, I promise to promote R as often as I can here on our faculty (which still uses Statistica for almost everything) thanks a million in advance !
Gabor Grothendieck
2004-Jun-18 12:34 UTC
[R] [Q] Newbie (continued.. at least I got R running allready :-)
Check out ?turnpoints in the pastecs library. Try example(turnpoints) str(Nauplii.tp) to see the data structure you get back. It identifies the peaks and pits and other associated information. Date: Fri, 18 Jun 2004 11:23:54 +0200 From: jeroen clarysse <jeroen.clarysse at easynet.be> To: <r-help at stat.math.ethz.ch> Subject: [R] [Q] Newbie (continued.. at least I got R running allready :-) Hi all a week ago, I posted a newbie question in data smoothing & maximum-extraction with R. I got quite a lot of response, but I'm still kinda stuck with it... I'll restate the problem : i got a datafile with 2400 measuerements (every 250msec) of a CO2 measurement device, capturing the breath of a subject. I uploaded such a sample here : http://www.psy.kuleuven.ac.be/leerpsy/data.csv now I wish to figure out where each breath expiration ceiling takes place , as shown on this graph : http://www.psy.kuleuven.ac.be/leerpsy/graph.bmp I'm kinda stuck on how to get this running in R. I really hope someone can help me out. If you guys can get me running, I promise to promote R as often as I can here on our faculty (which still uses Statistica for almost everything) thanks a million in advance !
Richard A. O'Keefe
2004-Jun-22 04:42 UTC
[R] [Q] Newbie (continued.. at least I got R running allready :-)
"jeroen clarysse" <jeroen.clarysse at easynet.be> wrote: I'll restate the problem : i got a datafile with 2400 measuerements (every 250msec) of a CO2 measurement device, capturing the breath of a subject. I uploaded such a sample here : http://www.psy.kuleuven.ac.be/leerpsy/data.csv I stuffed that through an AWK script to convert hh:mm:ss:msc to seconds and omit the INDEX field. Plotting the points, I noticed well-defined peaks, but they were flat-topped.> x <- read.table("leer.dat", header=TRUE)This table has $t and $co2 columns.> y <- rle(x$co2) > n <- 2:(length(y$values)-1) > b <- n[(y$values[n-1] < y$values[n]) & (y$values[n] > y$values[n+1])] > i <- cumsum(y$lengths)[b] > j <- i + 1 - y$lengths[b] > plot(x, col="green") # points in green > points(x[j,], col="red") # first point of each peak in red > points(x[i,], col="black") # last point of each peak in black> g <- diff((x$t[i]+x$t[j])/2)This step first finds the mid-points of the peaks, and then finds the differences between them.> g[1] 4.6125 3.3750 4.3875 3.4500 3.8625 3.6500 4.2750 3.9000 3.6750 4.8750 [11] 2.8375 2.9375 2.6875 2.3375 2.7375 2.4250 There is quite a dramatic difference between the first ten inter-peak times and the last five.