passing canberra distance function in in complex survey

45 Views Asked by At

I am trying apply the Canberra distance function in complex survey design using R package survey and srvyr.

example:

dstrata %>%
  group_by(awards) %>%
  summarise(api00 = survey_mean(api00),
            api99=survey_mean(api99))

I want to apply the canb.dist function to measure the distance between apo00 and api99

    canb.dist <- function(x, j){ sum((abs(x-j))/(abs(x)+abs(j)))}
    
    canberra.index= function(x,j){
    
    Canbdist=sum((abs(x-j))/(abs(x)+abs(j)))
    
    domain=numeric(length(x))

return (CD= Canbdist/domain)

}
1

There are 1 best solutions below

0
Thomas Lumley On

I don't know if anyone has defined a weighted version of the Canberra distance, but it's the total (or mean) of abs(x-y)/(abs(x)+abs(y), so

  1. Define a variable z=abs(x-y)/(abs(x)+abs(y))
  2. survey_mean(z) or survey_total(z)