开发者

R: Comparing oddly indexed vectors

I have some data with some hard to deal with properties. There are two vectors that are taking a measure of quality (from 0-1) at points along a physical object. These measurements are indexed according to the distance the measurement was taken from the bottom of the object. Then, a quality improving transformation is applied to the object, and measurements are taken again. However, the number of measurements are not the same, nor are the points on which they are taken.

In R, the data looks something like this (but with many more points)

Before transformation:

     value index
[1,]   0.3     6
[2,]   0.6    16
[3,]   0.1    25
[4,]   0.8    37
[5,]   0.2    46
[6,]   0.4    58
[7,]   0.4    64
[8,]   0.2    76

After transformation:

      value index
 [1,]   0.3     1
 [2,]   0.5     9
 [3,]   0.7    18
 [4,]   0.4    30
 [5,]   0.9    44
 [6,]   0.3    48
 [7,]   0.4    61
 [8,]   0.5    66
 [9,]   0.3    76
[10,]   0.1    85

Under the assumption that quality along the object is continuous (if not observed at every point), and that the ammount of improveme开发者_C百科nt during the tranformation is dependent on the point along the object, I would like to be able to show the distribution of quality improvement.

Since there are different numbers of measurements, and different indexes, I don't think

plot(density(after$value - before$value)) 

is what I'm looking for. My question is, is there a sane way to take that difference such that I have a number of observations for how much quality improved? Or am I going to be stuck looking at the difference in means?


Maybe this is what you want: you want to display a smoothed curve of Index vs Value for "before" the transformation and for "after" the transformation, on the same graph so you can visualize the general "improvement" in quality: I show this below with some simulated data.

bef <- .2 + 2*((1:1000)/1000 - .5)^2  + round(rnorm(1000),1)/100
aft <- bef * (1 + rnorm(1,.7,.2))
bef.samp <- sample(1:1000, 100)
aft.samp <- sample(1:1000, 60)
bef.df <- data.frame( value = bef[ bef.samp ], index = bef.samp )
aft.df <- data.frame( value = aft[ aft.samp ], index = aft.samp )
bef.aft <- rbind( cbind(when = 'bef', bef.df), cbind( when = 'aft', aft.df))
ggplot(bef.aft, aes(index,value)) + 
   geom_smooth(aes(colour = when), se=0, size=1) + 
      geom_point(aes(colour=when))

R: Comparing oddly indexed vectors

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜