Skip to content

Commit

Permalink
New option to adjust smoothness of kernel density estimator in Kernel…
Browse files Browse the repository at this point in the history
…R and KernelTimeR (#245)

* Add smoothness option to kde

* update docu

---------

Co-authored-by: Antonia Runge <[email protected]>
  • Loading branch information
mgross and arunge authored Sep 5, 2024
1 parent a783514 commit 65ed7a0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: DSSM
Title: Pandora & IsoMemo spatiotemporal modeling
Version: 24.09.0
Version: 24.09.1
Authors@R: c(
person("Marcus", "Gross", email = "[email protected]", role = c("cre", "aut")),
person("Antonia", "Runge", email = "[email protected]", role = c("aut"))
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# DSSM 24.09.1

## New Features
- _KernelR_ + _KernelTimeR_: New option to adjust smoothness of kernel density estimator

# DSSM 24.09.0

## Bug Fixes
Expand Down
16 changes: 13 additions & 3 deletions R/01-estimateMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,7 @@ invLogit <- function(x){
#' @param nClustRange numeric: range of potential mclust cluster
#' @param restriction numeric vector: spatially restricts model data 4 entries for latitude (min/max) and longitude(min/max)
#' @param nSim numeric: number of bootstrap samples
#' @param smoothness numeric: smoothness adjustment
#' @param kdeType character: "1" for correlated bandwidth, "2" for diagonal bandwidth, "3" for diagonal, equal long/lat bandwidth
#' @inheritParams centerData
#' @examples
Expand Down Expand Up @@ -2030,6 +2031,7 @@ estimateMapKernel <- function(data,
trimRatio = 0.05,
restriction = c(-90, 90, -180, 180),
nSim = 10,
smoothness = 1,
kdeType = "1"){
center <- match.arg(center)

Expand Down Expand Up @@ -2099,7 +2101,8 @@ estimateMapKernel <- function(data,
H = Hpi.diag(cbind(data3$Longitude, data3$Latitude))
diag(H) <- prod(diag(H)^0.5)
}

#smoothness adjustment
H = H*smoothness
kde(cbind(data3$Longitude, data3$Latitude), w = data3[,Weighting], H=H)
}),
silent = TRUE)
Expand All @@ -2116,7 +2119,8 @@ estimateMapKernel <- function(data,
H = Hpi.diag(cbind(data3$Longitude, data3$Latitude))
diag(H) <- prod(diag(H)^0.5)
}

#smoothness adjustment
H = H*smoothness
kde(cbind(data3$Longitude, data3$Latitude), H=H)
}), silent = TRUE)
}
Expand Down Expand Up @@ -2186,6 +2190,7 @@ estimateMapKernelWrapper <- function(data, input) {
kMeansAlgo = input$kMeansAlgo,
restriction = restriction,
nSim = input$nSim,

kdeType = input$kdeType)
}

Expand All @@ -2212,6 +2217,7 @@ estimateMapKernelWrapper <- function(data, input) {
#' @param dateUnc character: one of "uniform", "normal", "point"
#' @param restriction numeric vector: spatially restricts model data 4 entries for latitude (min/max) and longitude(min/max)
#' @param nSim numeric: number of bootstrap samples
#' @param smoothness numeric: smoothness adjustment
#' @param kdeType character: "1" for correlated bandwidth, "2" for diagonal bandwidth, "3" for diagonal, equal long/lat bandwidth
#' @inheritParams centerData
#' @examples
Expand Down Expand Up @@ -2245,6 +2251,7 @@ estimateMap3DKernel <- function(data,
dateUnc = "point",
restriction = c(-90, 90, -180, 180),
nSim = 10,
smoothness = 1,
kdeType = "1") {
center <- match.arg(center)

Expand Down Expand Up @@ -2377,7 +2384,8 @@ estimateMap3DKernel <- function(data,
H = Hpi.diag(cbind(data3$Longitude, data3$Latitude, data3$Date2))
diag(H)[1:2] <- prod(diag(H)[1:2]^0.5)
}

#smoothness adjustment
H = H*smoothness
kde(cbind(data3$Longitude, data3$Latitude, data3$Date2), H= H, w = data3[,Weighting])
}), silent = TRUE)
} else {
Expand All @@ -2400,6 +2408,8 @@ estimateMap3DKernel <- function(data,
H = Hpi.diag(cbind(data3$Longitude, data3$Latitude, data3$Date2))
diag(H) <- prod(diag(H)^0.5)
}
#smoothness adjustment
H = H*smoothness
kde(cbind(data3$Longitude, data3$Latitude, data3$Date2), H = H)}), silent = TRUE)
}

Expand Down
2 changes: 2 additions & 0 deletions R/03-modelResults2DKernel.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ modelResults2DKernelUI <- function(id, title = "", asFruitsTab = FALSE){
ns = ns
)
),
sliderInput(ns("smoothParam"), value = 1.0, min = 0.1, max = 5.0, step = 0.1, label = "Adjust smoothness (optional)"),
radioButtons(ns("kdeType"), "Bandwidth matrix type",
choices = c("Correlated" = "1", "Diagonal" = "2", "Diagonal + equal in longitudes and latitudes" = "3")),
actionButton( ns("start"), "Start"),
Expand Down Expand Up @@ -515,6 +516,7 @@ modelResults2DKernel <- function(input, output, session, isoData, savedMaps, fru
trimRatio = input$trimRatio,
restriction = restriction,
nSim = input$nSim,
smoothness = input$smoothParam,
kdeType = input$kdeType) %>%
tryCatchWithWarningsAndErrors()
},
Expand Down
2 changes: 2 additions & 0 deletions R/03-modelResults3DKernel.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ modelResults3DKernelUI <- function(id, title = ""){
ns = ns
)
),
sliderInput(ns("smoothParam"), value = 1.0, min = 0.1, max = 5.0, step = 0.1, label = "Adjust smoothness (optional)"),
radioButtons(ns("kdeType"), "Bandwidth matrix type",
choices = c("Correlated" = "1", "Diagonal" = "2", "Diagonal + equal in longitudes and latitudes" = "3")),
actionButton( ns("start"), "Start"),
Expand Down Expand Up @@ -627,6 +628,7 @@ modelResults3DKernel <- function(input, output, session, isoData, savedMaps, fru
modelUnc = input$modelUnc,
restriction = restriction,
nSim = input$nSim,
smoothness = input$smoothParam,
kdeType = input$kdeType) %>%
tryCatchWithWarningsAndErrors()
},
Expand Down
3 changes: 3 additions & 0 deletions man/estimateMap3DKernel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/estimateMapKernel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 65ed7a0

Please sign in to comment.