2

During the process of doing kernel density in R, using UK crime data as data set.

Below is the work I have done so far but encounter some issues:

library(ks)
library(raster) 
data1<-subset(data,select=c(Longitude, Latitude))
data1<-data[(complete.cases(data1)),]
Hpi <- Hpi.diag(x=data1,binned=TRUE,bgridsize=c(10000,10000))

Error in chol.default(S) : 
 the leading minor of order 1 is not positive definite
In addition: Warning message:
In var(x) : NAs introduced by coercion

fhat.diag <- kde(data1, H=Hpi, binned=TRUE)

Error in as.integer(x) : 
cannot coerce type 'closure' to vector of type 'integer'
str(data)

'data.frame':   6773 obs. of  13 variables:
 $ Crime.ID             : Factor w/ 6656 levels "00019a191b438730dfbccc03fc6494758f84bc095f1e0959450b40fef2586d48",..: 1453 866 100 969 3904 6480 4193 4657 1533 4786 ...
 $ Month                : Factor w/ 1 level "2014-02": 1 1 1 1 1 1 1 1 1 1 ...
 $ Reported.by          : Factor w/ 2 levels "City of London Police",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ Falls.within         : Factor w/ 2 levels "City of London Police",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ Longitude            : num  0.141 0.148 0.139 0.139 0.129 ...
 $ Latitude             : num  51.6 51.6 51.6 51.6 51.6 ...
 $ Location             : Factor w/ 4800 levels "On or near A1",..: 1769 3287 4795 4795 3327 3429 33 3808 236 157 ...
 $ LSOA.code            : Factor w/ 3218 levels "E01000002","E01000006",..: 15 15 16 16 16 16 16 17 17 17 ...
 $ LSOA.name            : Factor w/ 3218 levels "Barking and Dagenham 001A",..: 1 1 2 2 2 2 2 3 3 3 ...
 $ Borough              : Factor w/ 37 levels "Barking and Dagenham",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Crime.type           : Factor w/ 1 level "Burglary": 1 1 1 1 1 1 1 1 1 1 ...
 $ Last.outcome.category: Factor w/ 16 levels "Awaiting court outcome",..: 16 6 3 6 16 16 16 16 16 16 ...
 $ X                    : logi  NA NA NA NA NA NA ...


 class(data)

 [1] "data.frame"
  • We have no way of knowing what "data" and "data1" look like. Please provide some additional information on what your data format and object classes are. – Jeffrey Evans Aug 21 '16 at 14:14
  • Sorry the data1 is just to help select the complete crime cases from police UK. Will provide this info on. Thank you. – Wan Yu Lo Aug 21 '16 at 14:27
  • Followin @JeffreyEvans, please edit into your question the output of str(data) and / or of class(data) – dof1985 Aug 21 '16 at 14:30
  • @WanYuLo - please do not cancel format edits. This is a more proper way to display code snippet on GIS SE – dof1985 Aug 21 '16 at 14:32
  • Sorry, I was trying to figure out how to do. Is it okay now? Thanks. – Wan Yu Lo Aug 21 '16 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.