[R] lowess + turnpoints = doubling integers?
Bob Porter
rjporter at mindspring.com
Tue Dec 31 13:22:02 CET 2002
Hello Philippe:
Thank you for your interest. I have explored this and it appears to happen with
sequences in which small differences between successive occurrences, somewhere
in
turnpoints, but I have not tracked it down exactly. The following is a cobbled
together demo based on the original code. m b, Bob
***********************************************
foo<-rnorm(n=1200,mean=23.02, sd=34.14) #based on stat of actual data
xx<-lowess(foo,f=.04) #note that changing f or length of foo (equivalent,
actually) changes the result
yy<- turnpoints(xx$y)
onsets<-seq(1:yy$nturns)
peaks<-seq(1:yy$nturns)
offsets<-seq(1:yy$nturns)
ievent<-1
istart<-1
if(yy$firstispeak) istart<-2 #always start with a pit
i<-istart
adj<-1 #dummy adjustment, means something in original code
while(i<=yy$nturns-istart-adj)
{
# points are processed in sets of three pit-peak-pit events,
starting with a pit
onsets[ievent]<-yy$tppos[i+1]-yy$tppos[i]#i is the onset point for this
event, this calculates its duration
peaks[ievent]<-yy$tppos[i+1] #i+1 is the location of the peak point
offsets[ievent]<-yy$tppos[i+2]-yy$tppos[i+1] #calculate the offset
duration but subtracting peak point from offset point
i<-i+2 #set i to the offset point WHICH IS ALSO THE ONSET POINT FOR THE
NEXT EVENT
ievent<-ievent+1
#cat(i," ",ievent,"// ")
}
events<-onsets+offsets
cat("\n",events,"events n=", nevents,"\n")
cat(onsets,"onsets\n")
cat(offsets,"offsets\n","\n")
*****************************************
----- Original Message -----
From: "Philippe Grosjean" <phgrosjean at sciviews.org>
To: "Bob Porter" <rjporter at mindspring.com>
Cc: <r-help at stat.math.ethz.ch>
Sent: Tuesday, December 31, 2002 4:55 AM
Subject: RE: [R] lowess + turnpoints = doubling integers?
> Bob,
> Happy New Year. Could you, please, cook an example so as we could spot the
> problem?
> Best,
>
> Philippe Grosjean
>
> ...........]<(({°<...............<°}))><...............................
> ) ) ) ) )
> ( ( ( ( ( Dr. Philippe Grosjean
> ) ) ) ) )
> ( ( ( ( ( LOV, UMR 7093
> ) ) ) ) ) Station Zoologique
> ( ( ( ( ( Observatoire Océanologique
> ) ) ) ) ) BP 28
> ( ( ( ( ( 06234 Villefranche sur mer cedex
> ) ) ) ) ) France
> ( ( ( ( (
> ) ) ) ) ) tel: +33.4.93.76.38.16, fax: +33.4.93.76.38.34
> ( ( ( ( (
> ) ) ) ) ) e-mail: phgrosjean at sciviews.org
> ( ( ( ( ( SciViews project coordinator (http://www.sciviews.org)
> ) ) ) ) )
> .......................................................................
>
>
>
> -----Original Message-----
> From: r-help-admin at stat.math.ethz.ch
> [mailto:r-help-admin at stat.math.ethz.ch]On Behalf Of Bob Porter
> Sent: dimanche 29 décembre 2002 8:52
> To: r-help at stat.math.ethz.ch
> Subject: [R] lowess + turnpoints = doubling integers?
>
>
> Happy New Year, r-helpers!
>
> I am using lowess to smooth a scatter plot,
> xx<-lowess(xinput,f=.04) #defaults for other args
> followed by
> turnpoints(xx$y) #defaults for other args
>
> I plot the smoothed result as well as turnpoints (using yy$tppos) on top of
> raw
> data plot.
> Result is exactly as expected, graphically.
>
> For another purpose, I calcuate the difference between turnpoints
> (representing
> time intervals between turnspoints in my applicaiton), e.g.
>
> aduration[j]<-yy$tppos[i+1]-yytppos[i]
>
> This also appears to work as expected, HOWEVER, a typical list of such
> differences looks like:
> 22,33,22,11,33,44,33,33,11,33,44,66,33,22,.........
> there are, in some instances, three digit measure such as 110 or 106, etc.
> but
> the double-digit measures, although of the proper magnitude, seem to always
> be
> double integers 11 to 99.
>
> The double-integer results are found with f=.04 and total length of vector
> of
> 1200. With vector of length 1100 (same input data), the results are NOT
> double-integer but are ALWAYS (?) of the form x0, e.g.
> 70,50,50,70,100,40............ The magnitude of these latter results (22 vs
> 70,
> for example) is evidently due to the change in the smoothing span from
> .04*1200
> to .04*1100, but I am mystified why the results have double-integers in the
> first case, and terminal zeros in the second.
>
> My project involves applying these functions in a batch run for dozens of
> data
> sets so I want to understand more about what is going on that yeilds these
> strange double-integers or zero-terminating values.
>
> Thanks,
>
> Bob Porter, Tampa
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
>
>
More information about the R-help
mailing list