0

I have coordinates of road accident data and I want to use 2d kernel density with weighted observation by severity of accident: For example, I want fatal accident to be counted 3 times and damage only accident to be counted 1 time. How do I add it to the function? I notice that w in the function means that weights have to sum to sample size. Thank you!

NOA11120
  • 27
  • 5
  • kde(a[,1:2],w=numeric(length(x))+3), lets say all of the accidents are severe and I want them to be counted 3 times. only this works:kde(a[,1:2],w=numeric(length(x))+1). sum of w has to be sample size – NOA11120 Jan 18 '18 at 15:41
  • 1
    Can you post a minimal example please. – Sam Jan 18 '18 at 15:42
  • a=cbind(c(1,2,5,6),c(3,4,6,2)). coordinates of severe accidents – NOA11120 Jan 18 '18 at 15:47
  • 1
    Which package are you using? – Sam Jan 18 '18 at 15:53
  • im using ks package – NOA11120 Jan 18 '18 at 16:05
  • 1
    Ok so in a object you have provided, how do I know which is a fatal accident compared to a non-fatal accident? – Sam Jan 18 '18 at 16:26
  • Doesnt really matter. lets say the first 2 are fatal and the other 2 are damage only. How do I count the fatal ones 3 times? – NOA11120 Jan 29 '18 at 15:39
  • By providing a vector of weights which correspond to your training examples (usually). Your training data will be labelled, therefore it should be easy to create a vector of the same length. – Sam Jan 29 '18 at 16:11
  • w=c(3,3,1,1) for example? In kde function the sum of w has to be equal to sample size which is 4. but here sum(w)=8. – NOA11120 Jan 30 '18 at 13:50
  • On a default model, check the length of the weights vector. By default the weight vector is filled with 1's. I feel you may be getting confused with the length of the weight vector must equal the number of data points in your training data. – Sam Jan 30 '18 at 14:34

0 Answers0