When I plot the density for wind direction using circular
package, I get an error. The error is shown below. Can someone explain the bw (bandwidth) that I need for the amount of data?
plot(density(dirCir))
Error in density.circular(dirCir) :
argument "bw" is missing, with no default
This is the actual code that I have.
library (circular)
dir <-c(308,351,330,16,3,346,345,345,287,359,345,358,336,335,346,16,325,354,5,354,322,340,6,278,354,343,261,353,288,8)
dirCir <- circular(dir, units ="degrees", template = "geographics")
mean(dirCir)
var(dirCir)
summary(dirCir)
plot(dirCir)
plot(density(dirCir))
rose.diag(dirCir, main = 'dir Data')
points(dirCir)
When you run density
on an object of class circular
, it appears that you have to include a value for bw
(bandwidth) explicitly (as the error message indicates). Try this:
plot(density(dirCir, kernel="wrappednormal", bw=0.02), ylim=c(-1,5))
See below for the graph. The ylim
range is so that the plot fits inside the plot area without clipping. See the help for density.circular
for more info on running the density
function on circular
objects.
As @eipi10 says, bw
has to be explicitly chosen. Depending on the kernel that you choose large and small values of this bandwidth parameter may produce spiky density estimates as well as very smooth ones.
Common practice is to try several values and choose the one that seems to describe the data best. However, note that the following functions provide more objective ways of selecting the bw
:
# bw.cv.mse.circular(dirCir)
[1] 21.32236
# bw.cv.mse.circular(dirCir, kernel = "wrappednormal")
[1] 16.97266
# bw.cv.ml.circular(dirCir)
[1] 19.71197
# bw.cv.ml.circular(dirCir, kernel = "wrappednormal")
[1] 0.2280636
# bw.nrd.circular(dirCir)
[1] 14.63382
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.