Skip to content

Commit

Permalink
external functions are not imported directly
Browse files Browse the repository at this point in the history
  • Loading branch information
SpatLyu committed Jun 24, 2024
1 parent dbb9dc0 commit 9886fd4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 70 deletions.
35 changes: 0 additions & 35 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,4 @@ export(gos)
export(gos_bestkappa)
export(inverse_bcPower)
export(sandwich)
importFrom(dplyr,all_of)
importFrom(dplyr,group_by)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,pick)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(dplyr,ungroup)
importFrom(ggplot2,aes)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme_bw)
importFrom(ggrepel,geom_label_repel)
importFrom(magrittr,"%>%")
importFrom(parallel,clusterExport)
importFrom(parallel,makeCluster)
importFrom(parallel,parLapply)
importFrom(parallel,stopCluster)
importFrom(purrr,map_dfr)
importFrom(sf,st_area)
importFrom(sf,st_as_sf)
importFrom(sf,st_drop_geometry)
importFrom(sf,st_geometry)
importFrom(sf,st_intersection)
importFrom(sf,st_join)
importFrom(sf,st_union)
importFrom(stats,as.formula)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(stats,var)
importFrom(tibble,as_tibble)
importFrom(tidyr,replace_na)
41 changes: 14 additions & 27 deletions R/gos.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@
#' object.
#'
#' @return A tibble made up of predictions and uncertainties.
#'
#' @importFrom stats as.formula sd quantile
#' @importFrom parallel makeCluster stopCluster parLapply
#' @importFrom tibble as_tibble
#' @importFrom purrr map_dfr
#' @importFrom dplyr select
#' @export
#'
#' @examples
#' \dontrun{
Expand All @@ -36,9 +31,6 @@
#' data = zn, newdata = grid, kappa = 0.08,cores = 6)
#' g
#' }

#' @export

gos = \(formula, data = NULL, newdata = NULL, kappa = 0.25, cores = 1){
doclust = FALSE
tau = 1 - kappa
Expand Down Expand Up @@ -74,22 +66,22 @@ gos = \(formula, data = NULL, newdata = NULL, kappa = 0.25, cores = 1){
obs_explanatory = as.matrix(obs_explanatory)
pred_explanatory = as.matrix(pred_explanatory)
xall = rbind(obs_explanatory, pred_explanatory)
sdv = sapply(1:nv, \(x) sd(xall[,x]))
sdv = sapply(1:nv, \(x) stats::sd(xall[,x]))

calculgos = \(u){
xpredvalues = pred_explanatory[u,]
ej1 = lapply(1:nv, \(x) Ej(obs_explanatory[,x], xpredvalues[x], np, sdv[x]))
ej = do.call(pmin, ej1)
k = which(ej >= quantile(ej, tau))
k = which(ej >= stats::quantile(ej, tau))
ej2 = ej[k]

c(sum(response[k] * ej2) / sum(ej2),
1 - quantile(ej2, 0.9),
1 - quantile(ej2, 0.95),
1 - quantile(ej2, 0.99),
1 - quantile(ej2, 0.995),
1 - quantile(ej2, 0.999),
1 - quantile(ej2, 1)) -> pred_unce
1 - stats::quantile(ej2, 0.9),
1 - stats::quantile(ej2, 0.95),
1 - stats::quantile(ej2, 0.99),
1 - stats::quantile(ej2, 0.995),
1 - stats::quantile(ej2, 0.999),
1 - stats::quantile(ej2, 1)) -> pred_unce
names(pred_unce) = c('pred',paste0('uncertainty',
c(90, 95, 99, 99.5, 99.9, 100)))
return(pred_unce)
Expand Down Expand Up @@ -133,13 +125,7 @@ gos = \(formula, data = NULL, newdata = NULL, kappa = 0.25, cores = 1){
#' object.
#'
#' @return A list of the result of the best kappa and the computation process curve.
#'
#' @importFrom stats as.formula
#' @importFrom dplyr summarise
#' @importFrom parallel makeCluster stopCluster clusterExport parLapply
#' @importFrom purrr map_dfr
#' @importFrom ggplot2 ggplot aes geom_point geom_line scale_x_continuous scale_y_continuous theme_bw
#' @importFrom ggrepel geom_label_repel
#' @export
#'
#' @examples
#' \dontrun{
Expand All @@ -156,7 +142,6 @@ gos = \(formula, data = NULL, newdata = NULL, kappa = 0.25, cores = 1){
#' b1$bestkappa
#' b1$plot
#' }
#' @export

gos_bestkappa = \(formula, data = NULL, kappa = seq(0.05,1,0.05),
nrepeat = 10,nsplit = 0.5,cores = 1){
Expand Down Expand Up @@ -216,10 +201,12 @@ gos_bestkappa = \(formula, data = NULL, kappa = seq(0.05,1,0.05),
best_x = cv.out$kappa[k]
best_y = cv.out$rmse[k]

p1 = ggplot2::ggplot(cv.out, aes(x = kappa, y = rmse))+
p1 = ggplot2::ggplot(cv.out,
ggplot2::aes(x = kappa, y = rmse))+
ggplot2::geom_point()+
ggplot2::geom_line() +
ggrepel::geom_label_repel(data = data.frame(kappa=best_x, rmse=best_y),
ggrepel::geom_label_repel(data = data.frame(kappa = best_x,
rmse = best_y),
label=as.character(best_kappa)) +
ggplot2::scale_x_continuous(limits = c(0,1), breaks = seq(0,1,0.2)) +
ggplot2::scale_y_continuous(limits = c(min(cv.out$rmse) - l1,
Expand Down
9 changes: 3 additions & 6 deletions R/sandwich.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#' Default is `area`.
#'
#' @return A `sf` object with estimated mean `sandwichest_mean` and standard error `sandwichest_standarderror`.
#' @importFrom sf st_as_sf st_join st_drop_geometry st_intersection st_union
#' @importFrom dplyr group_by pick group_by summarise n ungroup select left_join mutate all_of
#' @importFrom tidyr replace_na
#' @importFrom stats var
#' @export
#'
#' @examples
Expand All @@ -34,8 +30,9 @@
#'sandwich(sampling = sampling,stratification = ssh,reporting = reporting,
#' sampling_attr = 'Value',ssh_zone = 'X',reporting_id = 'Y',
#' weight_type = 'area')
sandwich = \(sampling,stratification,reporting,sampling_attr,ssh_zone,
reporting_id,weight_type = 'area'){
#'
sandwich = \(sampling,stratification,reporting,sampling_attr,
ssh_zone, reporting_id, weight_type = 'area'){
if (!inherits(sampling,"sf")){
sampling = sf::st_as_sf(sampling)
}
Expand Down
2 changes: 0 additions & 2 deletions R/spEcula_helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ CalRMSE = \(yobse,ypred){
}

#' @title Rename sf object geometry name
#' @importFrom sf st_geometry
#' @noRd
st_rename_geometry = \(g, name){
current = attr(g, "sf_column")
Expand All @@ -41,7 +40,6 @@ st_rename_geometry = \(g, name){
}

#' @title Calculate the area of the polygon element using the specified unit
#' @importFrom sf st_area
#' @noRd
st_geographical_area = \(g){
garea = g %>%
Expand Down
1 change: 1 addition & 0 deletions man/sandwich.Rd

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

0 comments on commit 9886fd4

Please sign in to comment.