I have a series of highly accurate measurements named TrueDist and TrueVal. I also have a much larger data set with a large amount of uncertainty in the Distance measurement labelled Relativedist which is paired with the value measurement Relativeval.
I am looking to fit an offset to the Relativedist parameter so I can directly compare the highly accurate measurements with the higher volume measurement.
Data
Relativedist<-c(-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10)
Relativeval<-c(0.843,3.051,8.29,16.94,26.00,30,26.006,16.941,8.293,3.051,0.843,0.175,0.0279,0.0032,0.00028,0.00001)
TrueDist<-c(-3,1,3,5,8)
TrueVal<-c(17,29,16.8,3,0.03)
The way I was thinking of doing this was by setting a function
DistCorrect<-function(TrueDist,Relativedist,Relativeval,param){
(Relativeval/(Relativedist+param[1]))*TrueDist
}
Then using a least squares optimiser
lsfunc<-function(param,TrueVal,TrueDist,Relativedist,Relativeval){
eta<-DistCorrect(TrueDist,Relativedist,Relativeval,param)
sum((par - eta)^2)
}
initial guess
startparam<-c(2)
optimiser
optval<-optim(startparam,lsfunc,NULL,method="Nelder-Mead",control=c(maxit=1000,reltol=1e-8),TrueVal,TrueDist,Relativedist,Relativeval)
print(optval)
But this doesn't seem to work, I think due to the unbalanced samples. How I can fix this problem?