[R] Help on sound identification of "distance between lines"

Andras Farkas motyocska at yahoo.com
Sat May 11 12:49:11 CEST 2013


Dear List

I would like to ask for some input on the following (here is a simplified version of the code):

t <-t(seq(0,120,by=120/48))
d <-500
k <-0.1
x <-matrix((d/20)*exp(-k*0.9*t))
y <-matrix((d/15)*exp(-k*0.7*t))
z<-matrix((d/22)*exp(-k*1.1*t))
w<-matrix((d/17)*exp(-k*0.2*t))
t <-matrix(seq(0,120,by=120/48))
plot(t,x,type="l",ylab="Response",xlab="Time (h)")
lines(t,y,col="green")
lines(t,z,col="blue")
lines(t,w,col="yellow")
sim <-t(cbind(x,y,z,w))
true <-t((d/19)*exp(-k*0.35*t))
lines(t,true,col="red")

#find closest line
M <- rbind(sim, true) 
D <- as.matrix(dist(M)) 
diag(D) <- NA 
which.min(tail(D, 1))

In reality sim will consist of 5000 rows. My goal here is to use a sound method to find the row in sim that is most identical or closest to true (represented by the red line in the plot) taking into consideration the whole time interval evaluated. 

as always, thanks for the input...

Andras



More information about the R-help mailing list