# Loading R packages and input datasets for cluster analysis (R-3.5.0) library(SpatialEpi) library(maps) require(maptools) poland.map<-readShapePoly("poviats.shp",verbose=TRUE) deaths_files<-read.csv("lung_men.csv", header=TRUE, sep=";", dec=",") population_files<-read.csv("population_men.csv", header=TRUE, sep=";", dec=",") # Data preparation, including calculation of age-adjusted mortality rates geo <- latlong2grid(cbind(poland.map$X, poland.map$Y)) population <- tapply(population_files$NUMBER, population_files$TERYT, sum) cases <- tapply(deaths_files$NUMBER, deaths_files$TERYT, sum) expected.cases <- expected(population_files$NUMBER, deaths_files$NUMBER, 18) # Parameters specification pop.upper.bound <- 0.10 n.simulations <- 9999 alpha.level <- 0.001 plot <- TRUE # Identification of clusters using spatial scan statistic poisson <- kulldorff(geo, cases, population, expected.cases, pop.upper.bound, n.simulations, alpha.level, plot) cluster <- poisson$most.likely.cluster$location.IDs.included poisson$most.likely.cluster poisson$secondary.clusters # Loading R packages and input datasets for spatial regression library("sphet") library(spdep) # Loading spatial weights, coordinates of counties (LAU 1) and distances between them polgal <- read.gal("weights_poviats.GAL",override.id=TRUE) listw <- nb2listw(polgal) listw coordinates<-read.csv("poviats_coordinates.csv", header=FALSE, sep=";", dec=",") id1 <- seq(1, nrow(coordinates)) tmp <- distance(coordinates, region.id = id1, output = TRUE, type = "NN", nn = 10, shape.name = "shapefile", region.id.name = "id1", firstline = TRUE, file.name = "poviats.GWT") coldist <- read.gwt2dist(file = "poviats.GWT", region.id = id1, skip = 1) # Loading input dataset and fitting spatial regression data_by_poviats<-read.csv("TGI_aggregated_data.csv", header=TRUE, sep=";", dec=",") res <- stslshac(AGE_ADJUSTED_LUNG_CANCER_MORTALITY ~ CIGARETTES_USERS + FISH_CUNSUMPTION + SUCROSE_INTAKE, data = data_by_poviats, listw, distance = coldist, type = "Triangular", HAC = TRUE) summary(res) res <- stslshac(AGE_ADJUSTED_LUNG_CANCER_MORTALITY ~ CIGARETTES_USERS + FISH_CONSUMPTION + SUCROSE_INTAKE + WAGES_SALARIES + REGISTERED_UNEMPLOYMENT + OUTPATIENT_DEPARTMENTS, data = data_by_poviats, listw, distance = coldist, type = "Triangular", HAC = TRUE) summary(res)