GithubHelp home page GithubHelp logo

spatialepi's Introduction

SpatialEpi

R-CMD-check CRAN_Status_Badge CRAN RStudio mirror downloads

Package of data and methods for spatial epidemiology.

Installation

Get the released version from CRAN:

install.packages("SpatialEpi")

Or the development version from GitHub:

# If you haven't installed devtools yet, do so:
# install.packages("devtools")
devtools::install_github("rudeboybert/SpatialEpi")

Note: In order for all C++ code to compile correctly you may need to

  1. Install the cpp11 package

  2. Install an older version of RcppArmadillo by running

    packageurl <- "https://cran.r-project.org/src/contrib/Archive/RcppArmadillo/RcppArmadillo_0.9.900.3.0.tar.gz"
    install.packages(packageurl, repos=NULL, type="source")

Example

We load the data and convert the coordinate system from latitude/longitude to a grid-based system.

library(SpatialEpi)
data(NYleukemia)
sp.obj <- NYleukemia$spatial.polygon
centroids <- latlong2grid(NYleukemia$geo[, 2:3])
population <- NYleukemia$data$population
cases <- NYleukemia$data$cases

We plot the incidence of leukemia for each census tract.

plotmap(cases/population, sp.obj, log=TRUE, nclr=5)
points(grid2latlong(centroids), pch=4)

We run the Bayesian Cluster Detection method from Wakefield and Kim (2013):

y <- cases
E <- expected(population, cases, 1)
max.prop <- 0.15
shape <- c(2976.3, 2.31)
rate <- c(2977.3, 1.31)
J <- 7
pi0 <- 0.95
n.sim.lambda <- 10^4
n.sim.prior <- 10^5
n.sim.post <- 10^5

# Compute output
output <- bayes_cluster(y, E, population, sp.obj, centroids, max.prop,
                        shape, rate, J, pi0, n.sim.lambda, n.sim.prior,
                        n.sim.post)
#> [1] "Algorithm started on: Thu Jun 10 16:38:10 2021"
#> [1] "Importance sampling of lambda complete on: Thu Jun 10 16:39:11 2021"
#> [1] "Prior map MCMC complete on: Thu Jun 10 16:43:03 2021"
#> [1] "Posterior estimation complete on: Thu Jun 10 16:56:47 2021"
plotmap(output$post.map$high.area, sp.obj)
#> Warning in wkt(obj): CRS object has no comment

#> Warning in wkt(obj): CRS object has no comment

spatialepi's People

Contributors

arrismo avatar idblr avatar rudeboybert avatar whoishomer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

spatialepi's Issues

Update install_geo_libraries vignette

  • You really must not recommend the use of MacPorts. Proper, static
    builds of gdal and geos are available from mac.r-project.org, and binary
    macOS packages for rgeos and rgdal are available, And you do not need
    to use a terminal to download and install packages: it can and probably
    should be done from inside R, either via install.packages() or from the
    GUI menus.

Similarly, Windows users can just use binary packages. OSGeo4W is not
needed even when installing from source.

Then vignette back into package

Fix Error: package or namespace load failed for 'SpatialEpi' in dyn.load(file, DLLpath = DLLpath, ...)

unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/00LOCK-SpatialEpi/00new/SpatialEpi/libs/SpatialEpi.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/00LOCK-SpatialEpi/00new/SpatialEpi/libs/SpatialEpi.so, 6): Library not loaded: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libR.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/00LOCK-SpatialEpi/00new/SpatialEpi/libs/SpatialEpi.so
Reason: image not found
Error: loading failed
Execution halted
ERROR: loading failed

  • removing '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/SpatialEpi'
  • restoring previous '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/SpatialEpi'

Error in kulldorff function for cincinnati data

Hello, I'm working on the Cincinnati data from the paper "Grubesic, T, R. Wei and A. Murray (2014). Spatial clustering overview and comparison: accuracy, sensitivity and computational expense. Annals, Association of American Geographers 104, 1134-1156.", available at GeoDat github repo.

This is the format of the data:

> str(cincinnati, max.level = 1)
    Classes ‘sf’ and 'data.frame':	457 obs. of  73 variables:
    $ ID        : num  726907 695744 695762 695780 695798 ...
    $ POPULATION: num  479 85 29 117 96 45 81 32 41 89 ...
    $ ASSAULT   : int  0 2 0 3 0 9 1 1 0 1 ...
    $ geometry  :sfc_POLYGON of length 457; first list element: List of 1

I assigned the arguments geo and expected.cases like this:

geo = cincinnati %>% group_by(ID) %>% summarise(st_centroid(geometry)) %>% st_coordinates() %>% as.data.frame()
EC = expected(cincinnati$POPULATION, cincinnati$ASSAULT, 1) # I used  n.strata = 1 because it returns a vector of 457 elements (just like cincinnati$ASSAULT or cincinnati$POPULATION)

Now, when I call the function kulldorff, i get the error: "Error in hist.default(combined.lambda, main = "Monte Carlo Distribution of Lambda", : invalid number of 'breaks' "

poisson <- kulldorff(geo,                     # an n x 2 table of the (x,y)-coordinates of the area centroids
                     cincinnati$ASSAULT,      # aggregated case counts for all n areas
                     cincinnati$POPULATION,   # aggregated population counts for all n areas
                     expected.cases=EC,       # expected numbers of disease for all n areas 
                     pop.upper.bound=0.5,     # the upper bound on the proportion of the total population each zone can include
                     n.simulations=999,       # number of Monte Carlo samples used for significance measures
                     alpha.level=0.05,        # alpha-level threshold used to declare significance
                     plot=TRUE                # flag for whether to plot histogram of Monte Carlo samples of the LL of the most likely cluster
                     )

If I change the argument plot = FALSE, i get the error: "Error in if (new.secondary.cluster$p.value > alpha.level) { : missing value where TRUE/FALSE needed "

At this point I don't understand how can I fix it from the arguments, can you please help me indicating how can I solve it?, finally, my setup enviroment in R is:

R version 4.2.3 (2023-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] tools     stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] SpatialEpi_1.2.8 sp_1.6-0         sf_1.0-12        stringr_1.4.1   
[5] ggplot2_3.4.1    dplyr_1.1.1     

loaded via a namespace (and not attached):
 [1] spdep_1.2-8        Rcpp_1.0.10        pillar_1.9.0       compiler_4.2.3    
 [5] class_7.3-21       boot_1.3-28        lattice_0.20-45    lifecycle_1.0.3   
 [9] tibble_3.2.1       gtable_0.3.3       pkgconfig_2.0.3    rlang_1.1.0       
[13] DBI_1.1.3          cli_3.6.1          spData_2.2.2       e1071_1.7-13      
[17] s2_1.1.2           withr_2.5.0        generics_0.1.3     vctrs_0.6.1       
[21] classInt_0.4-9     grid_4.2.3         tidyselect_1.2.0   glue_1.6.2        
[25] R6_2.5.1           fansi_1.0.4        deldir_1.0-6       farver_2.1.1      
[29] magrittr_2.0.3     MASS_7.3-58.3      scales_1.2.1       units_0.8-1       
[33] colorspace_2.1-0   labeling_0.4.2     utf8_1.2.3         KernSmooth_2.23-20
[37] stringi_1.7.12     proxy_0.4-27       wk_0.7.2           munsell_0.5.0    

Add testthat unit tests

Add testthat unit tests on on kulldorff, besag, bayesian methods on a simple/toy example for README

Manuscript Error

Quitting from lines 139-144 (Manuscript.Rmd) Error in if (plot) { : argument is not interpretable as logical Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> kulldorff Execution halted

Write about pennLC in manuscript:

  • Talk about data source, year, geographic level, etc. i.e. give data's context (Use Pennsylvania Department of Health and link to new website for context)
  • Show users R code of how they could make static choropleth map of lung cancer cases

Convert all sp spatial data to sf package objects

  • pennLC. Arris will wait for Bert review.
  • Scotland
  • NY leukemia

sp is the old version of sf package for maps from 192. Currently pennLC data PA lung cancer data is saved very disorganized as follows:

library(SpatialEpi)
library(sp)
# case and population data
pennLC$data
# map data
pennLC$spatial.polygon

Goal: Create a sf data frame that allows you to create a choropleth map of the above data.

  1. Download a new shapefile of Pennsylvania that is county level
  2. Or convert PennLC$spatial.polygon into SF object
  3. Ensure that map and data-frame is attached (PennLC is the map)

As reference use https://r-pkgs.org/data.html?q=data-raw#data-sysdata
As example of workflow for adding data to R package, use 538:

Deliverable is an sf object that user can easily use to plot lung cancer data. target wednesday

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.