I'm analyzing traffic accidents with injuries and deaths of the Bogota city. The data contains the location of 9108 accidents of the year 2015 on a road network of 8218901 meters in length, they were divided by months and each month contain on overage 800 points (accidents). I am analyzing these data as a point pattern on a linear network using the spatstat package of R.
When I use density.lpp() with kernel Gaussian
## Todo.lpp it's the point pattern on the linear network
## npoints(Todo_lpp) = 9108 ; volume(domain(Todo_lpp)) = 8218901
density.lpp(Todo_lpp, sigma = 1000)
I obtain this "Error: $ operator is invalid for atomic vectors". With kernel Epanechnikov:
density.lpp(Todo_lpp, sigma = 1000, kernel = "epanechnikov")
I obtain: "Error in makeunitname(s[1], s[1]) : In unit name, first entry should be a character string".
To correct the error I used a server thinking that it was memory of the laptop and it didn't work. I tried with a some bandwith and I obtain the same error. I also tried decreasing the number of points and size of the network and the function density.lpp() worked for a point pattern on a network of 45113 meters in length with 102 events, but for a point pattern on a network of 129604.4 meters in length with 46 points didn't work.
- Does the density.lpp() function have any restrictions on the shape of the network of the point pattern?
- Is there any way to find an optimal bandwidth for smoothing kernel over a linear network?
- Does the density() function have any restrictions as to the number of points of the point pattern?
When I used: densidad_2015 <- density.lpp(Bogota_2015, sigma = 1000)
I obtain "Error: $ operator is invalid for atomic vectors", then I used traceback() and got the following :
..... 1, 1, 0.543675672992009, 0.917333284484343, 0.709566697706099,
1, 1, 0.377473064517719, 1, 0.310630352751969, 1, 0.490405224740971,
1, 1, 1))
5: do.call(X, append(as.list(coo), list(...)))
4: as.linim.linfun(f, ...)
3: as.linim(f, ...)
2: PDEdensityLPP(x, sigma, ..., weights = weights)
1: density.lpp(Bogota_2015, sigma = 1000)
When I used: densidad_2015 <- density.lpp(Bogota_2015, sigma = 5, kernel = "epanechnikov")
I obtain "Error in makeunitname(s[1], s[1]) :
In unit name, first entry should be a character string", then I used traceback() and got the following :
14: stop("In unit name, first entry should be a character string")
13: makeunitname(s[[1]], s[[1]])
12: as.unitname(x$units)
11: unitname.owin(W)
10: unitname(W)
9: as.unitname(unitname)
8: owin(W$xrange, W$yrange, poly = W$bdry, mask = W$m, unitname = unitname(W),
check = FALSE)
7: as.owin.owin(A)
6: as.owin(A)
5: is.subset.owin(i, as.owin(x))
4: `[.im`(Z, M, drop = FALSE)
3: Z[M, drop = FALSE]
2: linim(L, Z, df = df)
1: density.lpp(Bogota_2015, sigma = 5, kernel = "epanechnikov")
Below I attach the images of 2 of the 19 localities that Bogotá has with which I performed the tests of the function density.lpp().
The image with the blue road network corresponds to 46 points (the function density.lpp() didn't work) and the image with the green network to 102 points (the function density.lpp() worked).