File: LIK.density.spatial.single.R

package info (click to toggle)
r-cran-sparr 2.3-16-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: makefile: 2
file content (21 lines) | stat: -rw-r--r-- 644 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
LIK.density.spatial.single <- function(h,pp,res,edge,za){
  if(h<=0) return(NA)
  temp.dens.pts <- density(pp,sigma=h,edge=edge,dimyx=res,at="points",positive=FALSE,leaveoneout=TRUE,diggle=FALSE)/npoints(pp)
  
  ## tiny bandwidth protector action
  if(za==-1){
    dtest <- density(pp,sigma=h,edge=edge,dimyx=res,diggle=FALSE)
    if(any(dtest<=0)) return(-Inf)
  }
  
  if(any(temp.dens.pts<=0)){ 
    if(za==2){
      temp.dens.pts[temp.dens.pts<=0] <- min(temp.dens.pts[temp.dens.pts>0])
    } else if(za==1){
      temp.dens.pts <- posifybivden(temp.dens.pts)
    } else {
      return(-Inf)
    }
  }
  return(mean(log(temp.dens.pts)))
}