[R] measure smoothness
Ravi Varadhan
rvaradhan at jhmi.edu
Tue Nov 27 18:21:51 CET 2007
Assuming that the data are sampled at equal intervals, you can do the
following:
A <- matrix(scan("h:/test/junk.txt"), ncol=2, by=T) # I read your data in
# the following plots show that the 3rd set of data (in green) is smoothest
plot(A[1:11,1], A[1:11,2], type="o")
lines(A[12:22,1], A[12:22,2], type="o", col=2)
lines(A[23:33,1], A[23:33,2], type="o", col=3)
# Here are some numerical tests
# Roughly, average first-derivative
sqrt(mean(diff(A[1:11,2])^2))
sqrt(mean(diff(A[12:22,2])^2))
sqrt(mean(diff(A[23:33,2])^2))
# Roughly, average second-derivative
sqrt(mean(diff(A[1:11,2], diff=2)^2))
sqrt(mean(diff(A[12:22,2], diff=2)^2))
sqrt(mean(diff(A[23:33,2], diff=2)^2))
It is clear that the "new smoothed" data is the smoothest.
Ravi.
----------------------------------------------------------------------------
-------
Ravi Varadhan, Ph.D.
Assistant Professor, The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email: rvaradhan at jhmi.edu
Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
----------------------------------------------------------------------------
--------
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Al Lelopath
Sent: Tuesday, November 27, 2007 11:20 AM
To: r-help at r-project.org
Subject: [R] measure smoothness
I have 3 sets of Cartesian data, one is 'original' data and the other
2 are "smoothed"data. The smoothed data is the result of applying a
smoothing algorithm to the original.One set of smoothed data is the
'old' algorithm and the other set is the 'new' algorithm.
Does R have the capability of telling me which data is "smoother"?
Example data (subsets of entire data set):
original:
61 1.419584402
62 1.487019923
63 1.436887012
64 1.39522855
65 1.455934713
66 1.51774951
67 1.603945531
68 1.67847891
69 1.559326003
70 1.57563213
71 1.591873853
old smoothed:
61 1.337874627
62 1.391745721
63 1.387506435
64 1.382959722
65 1.413494505
66 1.445366725
67 1.474782643
68 1.474782643
69 1.474782643
70 1.474782643
71 1.500106199
new smoothed:
61 1.399345513
62 1.416106263
63 1.451252527
64 1.486278253
65 1.505360173
66 1.522991093
67 1.535206073
68 1.546861126
69 1.589831189
70 1.608288145
71 1.620107467
______________________________________________
R-help at 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.
More information about the R-help
mailing list