Title: | R Utilities Accompanying the Software Package BayesX |
---|---|
Description: | Functions for exploring and visualising estimation results obtained with BayesX, a free software for estimating structured additive regression models (<https://www.uni-goettingen.de/de/bayesx/550513.html>). In addition, functions that allow to read, write and manipulate map objects that are required in spatial analyses performed with BayesX. |
Authors: | Nikolaus Umlauf [aut, cre] , Thomas Kneib [aut], Nadja Klein [aut], Felix Heinzl [ctb], Andreas Brezger [ctb], Daniel Sabanes Bove [ctb] |
Maintainer: | Nikolaus Umlauf <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 0.3-3 |
Built: | 2024-12-13 06:39:44 UTC |
Source: | CRAN |
This package provides functionality for exploring and visualising estimation results obtained with the software package BayesX for structured additive regression. It also provides functions that allow to read, write and manipulate map objects that are required in spatial analyses performed with BayesX.
Nikolaus Umlauf, Thomas Kneib, Nadja Klein, Felix Heinzl, Andreas Brezger, Daniel Sabanes Bove
Belitz C, Brezger A, Kneib T, Lang S (2011). BayesX - Software for Bayesian Inference in Structured Additive Regression Models. Version 2.0.1. URL https://www.uni-goettingen.de/de/bayesx/550513.html.
Adds a neighborhhod relationship between two given regions to a map object in graph format.
add.neighbor(map, region1, region2)
add.neighbor(map, region1, region2)
map |
Map object in graph format that should be modified. |
region1 , region2
|
Names of the regions that should be connected as neighbors. |
Returns an adjacency matrix that represents the neighborhood structure of map
plus the new neighborhood relation in graph format.
Felix Heinzl, Thomas Kneib
get.neighbor
,delete.neighbor
,read.gra
,write.gra
bnd2gra
germany <- read.gra(system.file("examples/germany.gra", package="BayesX")) get.neighbor(germany, c("1001", "7339")) germany <- add.neighbor(germany, "7339", "1001") get.neighbor(germany, c("1001", "7339"))
germany <- read.gra(system.file("examples/germany.gra", package="BayesX")) get.neighbor(germany, c("1001", "7339")) germany <- add.neighbor(germany, "7339", "1001") get.neighbor(germany, c("1001", "7339"))
Converts a map in boundary format to a map in graph format.
bnd2gra(map)
bnd2gra(map)
map |
Map in boundary format that should be converted. |
Returns an adjacency matrix that represents the neighborhood structure of the map object in graph format.
Felix Heinzl, Thomas Kneib
BayesX Reference Manual. Available from https://www.uni-goettingen.de/de/bayesx/550513.html
read.bnd
,read.gra
,write.bnd
,write.gra
tanzania.bnd <- read.bnd(system.file("examples/tanzania.bnd", package="BayesX")) tanzania.gra <- bnd2gra(tanzania.bnd)
tanzania.bnd <- read.bnd(system.file("examples/tanzania.bnd", package="BayesX")) tanzania.gra <- bnd2gra(tanzania.bnd)
Creates a map object from a list of coordinates by treating observations within a certain distance as neighbors. The resulting neighborhood structure is stored in a map object in graph format while a map in boundary format is created to enable visualisation.
createxymap(x, y, districts=NULL, p=2, max.dist)
createxymap(x, y, districts=NULL, p=2, max.dist)
x |
Vector of x-coordinates of underlying points |
y |
Vector of y-coordinates of underlying points |
districts |
Either |
p |
Any p-norm with p>=1 can be chosen as the distance measure with the Euclidian distance ( |
max.dist |
Value which determines the neighborship. Points whose distance is smaller or equal than |
List of two elements: map object in graph format and map object in boundary format.
Felix Heinzl, Thomas Kneib
x <- c(3,3,5,9.5,11,11) y <- c(2,4,4,6,4.5,5) xymap <- createxymap(x, y, districts=c("A","B","C","D","E","F"), max.dist=2) xymap$gra drawmap(map=xymap$bnd)
x <- c(3,3,5,9.5,11,11) y <- c(2,4,4,6,4.5,5) xymap <- createxymap(x, y, districts=c("A","B","C","D","E","F"), max.dist=2) xymap$gra drawmap(map=xymap$bnd)
Adds the neighborhhod relationship between two given regions from a map object in graph format.
delete.neighbor(map, region1, region2)
delete.neighbor(map, region1, region2)
map |
Map object in graph format that should be modified. |
region1 , region2
|
Names of the regions that should no longer be regarded as neighbors. |
Returns an adjacency matrix that represents the neighborhood structure of map
minus the deleted neighborhood relation in graph format.
Felix Heinzl, Thomas Kneib
get.neighbor
,add.neighbor
,read.gra
,write.gra
bnd2gra
germany <- read.gra(system.file("examples/germany.gra", package="BayesX")) get.neighbor(germany, c("7339")) germany <- delete.neighbor(germany, "7339", "7141") get.neighbor(germany, c("7339"))
germany <- read.gra(system.file("examples/germany.gra", package="BayesX")) get.neighbor(germany, c("7339")) germany <- delete.neighbor(germany, "7339", "7141") get.neighbor(germany, c("7339"))
Visualises variables that are spatially aligned according to a given map object. Each of the regions in a map will be coloured accoring to the value of the variable.
drawmap(data, map, regionvar=2, plotvar=3, limits, cols="hcl", nrcolors=100, swapcolors=FALSE, pcat=FALSE, hcl.par=list(h=c(120, 0), c=60, l=c(45,60), power=1.2), hsv.par=list(s=1, v=1), legend=TRUE, drawnames=FALSE, cex.names=0.7, cex.legend=0.7, mar.min=2, density=15, ...)
drawmap(data, map, regionvar=2, plotvar=3, limits, cols="hcl", nrcolors=100, swapcolors=FALSE, pcat=FALSE, hcl.par=list(h=c(120, 0), c=60, l=c(45,60), power=1.2), hsv.par=list(s=1, v=1), legend=TRUE, drawnames=FALSE, cex.names=0.7, cex.legend=0.7, mar.min=2, density=15, ...)
data |
Either the name of a file or a data frame containing the variables to be visualised. If missing, the map will be visualised without superposition of any further information |
map |
Map object containing the required boundary information (as obtained by a call to |
regionvar |
Defines the variable specifying the geographical regions. Either the name of a variable in |
plotvar |
Defines the variable that should be visualised. Either the name of a variable in |
limits |
Restricts (or extends) the coloring scheme to a range of values. |
cols |
Color scheme to be employed. Could be either a vector of colors or one out of the following pre-defined schemes: |
nrcolors |
Number of colors (only meaningful when using one of the pre-defined colour schemes). |
swapcolors |
Reverse the order of colors (works also with user-specified colours but will be most usefule with the pre-defined schemes). |
pcat |
Option for the visualisation of posterior probabilities. In this case, a three-colour scheme representing significantly positive, insignificant and significantly negative values. |
hcl.par |
Parameters for the |
hsv.par |
Parameters for the |
legend |
Should a legend be added to the figure? |
drawnames |
Adds the name of each region as a text label to the plot. In most cases the result will be confusing but may be useful when checking the validity of a map. |
cex.names |
Magnification to be used for the names (if |
cex.legend |
Magnification to be used for the legend. |
mar.min |
Controls the definition of boundaries. Could be either |
density |
Regions without data will be visualised with diagonal stripes. |
... |
Further arguments to be passed to the plot calls that visualise the region boundaries (probably not useful at all). |
Felix Heinzl, Thomas Kneib, Andreas Brezger
germany <- read.bnd(system.file("examples/germany.bnd", package="BayesX")) drawmap(map=germany) drawmap(map=germany, drawnames=TRUE) res <- read.table(system.file("examples/spatial_f_regions_spatial.res", package="BayesX"), header=TRUE) drawmap(res, map=germany) drawmap(res, map=germany, limits=c(-2,4)) drawmap(res, map=germany, regionvar="regions", plotvar="pmed") drawmap(res, map=germany, legend=FALSE) drawmap(res, map=germany, legend=FALSE, main="spatial effect") drawmap(res, map=germany, cols="hsv") drawmap(res, map=germany, swapcolors=TRUE, cols="hsv") drawmap(res, map=germany, cols="grey") drawmap(res, map=germany, cols=c('darkgreen','green','yellow','orange','red','darkred')) drawmap(res, map=germany, pcat=TRUE, cols="hcl") drawmap(res, map=germany, pcat=TRUE, cols="hsv") drawmap(res, map=germany, pcat=TRUE, cols="grey") drawmap(res, map=germany, nrcolors=10, cols="hcl") drawmap(res, map=germany, nrcolors=10, cols="hsv") drawmap(res, map=germany, nrcolors=10, cols="grey") drawmap(res, map=germany, cols="hcl", hcl.par=list(h=c(0,120), c=60, l=c(45,90), power=1.2)) drawmap(res, map=germany, cols="hcl", hcl.par=list(h=c(300,120), c=60, l=c(45,90), power=1.2)) drawmap(res, map=germany, cols="hcl", hcl.par=list(h=c(40,260), c=60, l=c(45,90), power=1.2)) drawmap(res, map=germany, cols="hsv", hsv.par=list(s=0.7, v=0.7))
germany <- read.bnd(system.file("examples/germany.bnd", package="BayesX")) drawmap(map=germany) drawmap(map=germany, drawnames=TRUE) res <- read.table(system.file("examples/spatial_f_regions_spatial.res", package="BayesX"), header=TRUE) drawmap(res, map=germany) drawmap(res, map=germany, limits=c(-2,4)) drawmap(res, map=germany, regionvar="regions", plotvar="pmed") drawmap(res, map=germany, legend=FALSE) drawmap(res, map=germany, legend=FALSE, main="spatial effect") drawmap(res, map=germany, cols="hsv") drawmap(res, map=germany, swapcolors=TRUE, cols="hsv") drawmap(res, map=germany, cols="grey") drawmap(res, map=germany, cols=c('darkgreen','green','yellow','orange','red','darkred')) drawmap(res, map=germany, pcat=TRUE, cols="hcl") drawmap(res, map=germany, pcat=TRUE, cols="hsv") drawmap(res, map=germany, pcat=TRUE, cols="grey") drawmap(res, map=germany, nrcolors=10, cols="hcl") drawmap(res, map=germany, nrcolors=10, cols="hsv") drawmap(res, map=germany, nrcolors=10, cols="grey") drawmap(res, map=germany, cols="hcl", hcl.par=list(h=c(0,120), c=60, l=c(45,90), power=1.2)) drawmap(res, map=germany, cols="hcl", hcl.par=list(h=c(300,120), c=60, l=c(45,90), power=1.2)) drawmap(res, map=germany, cols="hcl", hcl.par=list(h=c(40,260), c=60, l=c(45,90), power=1.2)) drawmap(res, map=germany, cols="hsv", hsv.par=list(s=0.7, v=0.7))
This is a convenience function to extract samples from a BayesX results directory, which processes the log file to e.g. convert the spline coefficients samples to function values samples.
extractSamples(directoryWithBasename, logfile = file.path(dirname(directoryWithBasename), "log.txt"))
extractSamples(directoryWithBasename, logfile = file.path(dirname(directoryWithBasename), "log.txt"))
directoryWithBasename |
The BayesX results directory with basename for the files (e.g. "results/test", if this was specified as outfile in BayesX for the bayesreg object) |
logfile |
The log file of the MCMC run, defaults to log.txt in the results directory. |
Returns a list with the extracted samples of effects and deviances as well as the prediction data.frame:
<function name> |
for P-Splines, Random Walks and spatial effects: a list with mcmc objects 'functionSamples' and 'varianceSamples' containing the respective effects/function and variance parameter samples. |
FixedEffects |
an mcmc object of all fixed simple parametric effects |
RandomEffects |
if there is at least one random effect in the model, this is a list, with elements in the first hierarchy being the group ID names, and elements in the second hierarchy being the names of the covariates. The leafs are the mcmc objects 'functionSamples' and 'varianceSamples', as for the other non-fixed terms |
Deviance |
an mcmc object with the (unstandardized and saturated) deviance |
means |
if the option |
scale |
an mcmc object with the possible scale parameter samples |
lassoCoefficients |
an mcmc object with the possible lasso regression parameter samples |
ridgeCoefficients |
an mcmc object with the possible ridge regression parameter samples |
PredictMeans |
data.frame corresponding to the possible predictmean file in the BayesX directory |
Additionally, entries for possibly remaining lasso or ridge variance parameters etc. are included in the return list.
You should be sure that only one MCMC run is saved in the given results directory in order to get sensible results out of this function.
Daniel Sabanes Bove, with contributions by Fabian Scheipl
## get the samples samples <- extractSamples(file.path(system.file("examples/samples", package="BayesX"), "res")) str(samples) ## check deviance convergence plot(samples$Deviance) ## fixed parametric effects plot(samples$FixedEffects) ## nonparametric effects: ## handy plot function to get means and pointwise credible intervals nonpPlot <- function(samplesMatrix, ...) { x <- as.numeric(colnames(samplesMatrix)) yMeans <- colMeans(samplesMatrix) yCredible <- t(apply(samplesMatrix, MARGIN=2, FUN=quantile, prob=c(0.025, 0.975), na.rm=TRUE)) matplot(x, cbind(yMeans, yCredible), type="l", lty=c(1, 2, 2), lwd=c(2, 1, 1), col=c(1, 2, 2), ...) } nonpPlot(samples$f_x1$functionSamples, xlab=expression(x[1]), ylab=expression(hat(f)(x[1]))) nonpPlot(samples$f_x2$functionSamples, xlab=expression(x[2]), ylab=expression(hat(f)(x[2]))) ## spatial effect tanzania <- read.bnd(file=system.file("examples/tanzania.bnd", package="BayesX")) drawmap(map=tanzania, data= with(samples$f_district, data.frame(name=colnames(functionSamples), estimate=colMeans(functionSamples))), regionvar="name", plotvar="estimate")
## get the samples samples <- extractSamples(file.path(system.file("examples/samples", package="BayesX"), "res")) str(samples) ## check deviance convergence plot(samples$Deviance) ## fixed parametric effects plot(samples$FixedEffects) ## nonparametric effects: ## handy plot function to get means and pointwise credible intervals nonpPlot <- function(samplesMatrix, ...) { x <- as.numeric(colnames(samplesMatrix)) yMeans <- colMeans(samplesMatrix) yCredible <- t(apply(samplesMatrix, MARGIN=2, FUN=quantile, prob=c(0.025, 0.975), na.rm=TRUE)) matplot(x, cbind(yMeans, yCredible), type="l", lty=c(1, 2, 2), lwd=c(2, 1, 1), col=c(1, 2, 2), ...) } nonpPlot(samples$f_x1$functionSamples, xlab=expression(x[1]), ylab=expression(hat(f)(x[1]))) nonpPlot(samples$f_x2$functionSamples, xlab=expression(x[2]), ylab=expression(hat(f)(x[2]))) ## spatial effect tanzania <- read.bnd(file=system.file("examples/tanzania.bnd", package="BayesX")) drawmap(map=tanzania, data= with(samples$f_district, data.frame(name=colnames(functionSamples), estimate=colMeans(functionSamples))), regionvar="name", plotvar="estimate")
Combines a list of several regions of a map object in boundary format into a single region.
fuse(map, regions, name)
fuse(map, regions, name)
map |
Map object in boundary format that should be modified. |
regions |
Vector of regions to be combined |
name |
Name that should be given to the region arising from fusing the specified regions. |
Map object in boundary format with the specified regions combined.
Nadja Klein
## Not run: map <- read.bnd(system.file("examples/germany9301.bnd", package = "BayesX")) drawmap(map = map, drawnames = TRUE) ## Vector of regions to be combined. regions <- c("1056","1060","1061") ## New name of combined region. newname <- "1" newmap <- fuse(map,regions,newname) drawmap(map = newmap, drawnames = TRUE) ## Vector of regions to be combined. germany <- read.bnd(system.file("examples/germany.bnd", package="BayesX")) drawmap(map = germany, drawnames = TRUE) regions <- c("9371","9373","9374","9471","9472","9474","9574") ## New name of combined region. newname <- "1" newmap <- fuse(germany, regions, newname) drawmap(map = newmap, drawnames = TRUE) ## End(Not run)
## Not run: map <- read.bnd(system.file("examples/germany9301.bnd", package = "BayesX")) drawmap(map = map, drawnames = TRUE) ## Vector of regions to be combined. regions <- c("1056","1060","1061") ## New name of combined region. newname <- "1" newmap <- fuse(map,regions,newname) drawmap(map = newmap, drawnames = TRUE) ## Vector of regions to be combined. germany <- read.bnd(system.file("examples/germany.bnd", package="BayesX")) drawmap(map = germany, drawnames = TRUE) regions <- c("9371","9373","9374","9471","9472","9474","9574") ## New name of combined region. newname <- "1" newmap <- fuse(germany, regions, newname) drawmap(map = newmap, drawnames = TRUE) ## End(Not run)
Computes all areas and centroids of the regions of a given map in boundary format.
get.centroids(map)
get.centroids(map)
map |
Map object in boundary format. |
Matrix of area and centroids.
Felix Heinzl, Thomas Kneib
germany <- read.bnd(system.file("examples/germany.bnd", package="BayesX")) centroids <- get.centroids(germany) centroids[1:10,] plot(c(2100,3700),c(6800,8500),type="n", xlab="", ylab="") for(i in 1:10){ polygon(germany[[i]]) region <- attr(germany,"names")[i] text(x=centroids[i,2]+50, y=centroids[i,3]+30, region, cex=0.7) } points(centroids[1:10,2:3], col='red', pch=16)
germany <- read.bnd(system.file("examples/germany.bnd", package="BayesX")) centroids <- get.centroids(germany) centroids[1:10,] plot(c(2100,3700),c(6800,8500),type="n", xlab="", ylab="") for(i in 1:10){ polygon(germany[[i]]) region <- attr(germany,"names")[i] text(x=centroids[i,2]+50, y=centroids[i,3]+30, region, cex=0.7) } points(centroids[1:10,2:3], col='red', pch=16)
Extracts the neighbors of a number of regions from a map in graph format.
get.neighbor(map, regions)
get.neighbor(map, regions)
map |
Map object in graph format. |
regions |
Vector of names of regions for which the neighbors should be axtracted. |
A list of vectors containing the neighbors of the elements in regions
.
Felix Heinzl, Thomas Kneib
germany <- read.gra(system.file("examples/germany.gra", package="BayesX")) get.neighbor(germany, "1001") get.neighbor(germany, c("1001", "7339"))
germany <- read.gra(system.file("examples/germany.gra", package="BayesX")) get.neighbor(germany, "1001") get.neighbor(germany, c("1001", "7339"))
Compute approximate HPD intervals out of MCMC-samples in BayesX
hpd(data, alpha = 0.05, ...) hpd.coda(data, alpha = 0.05)
hpd(data, alpha = 0.05, ...) hpd.coda(data, alpha = 0.05)
data |
Either the name of a file or a data frame containing the sample. |
alpha |
A numeric scalar in the interval (0,1) such that 1 - alpha is the target probability content of the intervals.. The default is alpha = 0.05. |
... |
Further parameters to be passed to the internal call of |
hpd
computes the HPD interval based on a kernel density estimate of the samples.
hpd.coda
computes the HPD interval with the function HPDinterval
available in
package coda
.
Nadja Klein
res <- read.table(system.file("examples/nonparametric_f_x_pspline_sample.raw", package="BayesX"), header = TRUE) hpd(res) hpd.coda(res)
res <- read.table(system.file("examples/nonparametric_f_x_pspline_sample.raw", package="BayesX"), header = TRUE) hpd(res) hpd.coda(res)
Convert neighborhood structure objects of class "nb" from R-package spdep to graph objects of class "gra" from R-package BayesX and vice versa.
nb2gra(nbObject) gra2nb(graObject)
nb2gra(nbObject) gra2nb(graObject)
nbObject |
neighborhood structure object of class "nb" |
graObject |
graph object of class "gra" |
Equivalent object in the other format.
Daniel Sabanes Bove
sp2bnd
, bnd2sp
for conversion
between the geographical information formats and
read.gra
, write.gra
for the interface to
the BayesX files.
## Not run: ## first nb to gra: if(requireNamespace("sf") & requireNamespace("spdep")) { library("sf") library("spdep") columbus <- st_read(system.file("etc/shapes/columbus.shp", package = "spdep")[1]) colNb <- poly2nb(columbus) ## ... here manual editing is possible ... ## then export to graph format colGra <- nb2gra(colNb) ## and save in BayesX file graFile <- tempfile() write.gra(colGra, file=graFile) ## now back from gra to nb: colGra <- read.gra(graFile) newColNb <- gra2nb(colGra) newColNb ## compare this with the original colNb ## only the call attribute does not match (which is OK): all.equal(newColNb, colNb, check.attributes=FALSE) attr(newColNb, "call") attr(colNb, "call") } ## End(Not run)
## Not run: ## first nb to gra: if(requireNamespace("sf") & requireNamespace("spdep")) { library("sf") library("spdep") columbus <- st_read(system.file("etc/shapes/columbus.shp", package = "spdep")[1]) colNb <- poly2nb(columbus) ## ... here manual editing is possible ... ## then export to graph format colGra <- nb2gra(colNb) ## and save in BayesX file graFile <- tempfile() write.gra(colGra, file=graFile) ## now back from gra to nb: colGra <- read.gra(graFile) newColNb <- gra2nb(colGra) newColNb ## compare this with the original colNb ## only the call attribute does not match (which is OK): all.equal(newColNb, colNb, check.attributes=FALSE) attr(newColNb, "call") attr(colNb, "call") } ## End(Not run)
Convert geographical information objects of class "SpatialPolygons" (or specializations) from R-package sp to objects of class "bnd" from R-package BayesX and vice versa.
sp2bnd(spObject, regionNames, height2width, epsilon) bnd2sp(bndObject)
sp2bnd(spObject, regionNames, height2width, epsilon) bnd2sp(bndObject)
spObject |
object of class "SpatialPolygons" (or specializations) |
regionNames |
character vector of region names (parallel to the Polygons list in spObject), defaults to the IDs |
height2width |
ratio of total height to width, defaults to the bounding box values |
epsilon |
how much can two polygons differ (in maximum squared Euclidean distance) and still match each other?, defaults to machine precision |
bndObject |
object of class "bnd" |
Equivalent object in the other format.
Daniel Sabanes Bove
nb2gra
, gra2nb
for conversion
between the neighborhood structure formats and
read.bnd
, write.bnd
for the interface to
the BayesX files.
## Not run: ## bnd to sp: germany <- read.bnd(system.file("examples/germany2001.bnd", package="BayesX")) spGermany <- bnd2sp(germany) ## plot the result together with the neighborhood graph library(sp) plot(spGermany) library(spdep) nbGermany <- poly2nb(spGermany) plot(nbGermany, coords=coordinates(spGermany), add=TRUE) ## example with one region inside another spExample <- spGermany[c("7211", "7235"), ] plot(spExample) plot(poly2nb(spExample), coords=coordinates(spExample), add=TRUE) ## now back from sp to bnd: bndGermany <- sp2bnd(spGermany) drawmap(map=bndGermany) ## compare names and number of polygons stopifnot(identical(names(bndGermany), names(germany)), identical(length(bndGermany), length(germany))) ## compare contains-relations surrounding <- attr(bndGermany, "surrounding") whichInner <- which(sapply(surrounding, length) > 0L) bndContainsData <- data.frame(inner=names(bndGermany)[whichInner], outer=unlist(surrounding)) surrounding <- attr(germany, "surrounding") whichInner <- which(sapply(surrounding, length) > 0L) originalContainsData <- data.frame(inner=names(germany)[whichInner], outer=unlist(surrounding)) stopifnot(all(bndContainsData[order(bndContainsData$inner), ] == originalContainsData[order(originalContainsData$inner), ])) ## End(Not run)
## Not run: ## bnd to sp: germany <- read.bnd(system.file("examples/germany2001.bnd", package="BayesX")) spGermany <- bnd2sp(germany) ## plot the result together with the neighborhood graph library(sp) plot(spGermany) library(spdep) nbGermany <- poly2nb(spGermany) plot(nbGermany, coords=coordinates(spGermany), add=TRUE) ## example with one region inside another spExample <- spGermany[c("7211", "7235"), ] plot(spExample) plot(poly2nb(spExample), coords=coordinates(spExample), add=TRUE) ## now back from sp to bnd: bndGermany <- sp2bnd(spGermany) drawmap(map=bndGermany) ## compare names and number of polygons stopifnot(identical(names(bndGermany), names(germany)), identical(length(bndGermany), length(germany))) ## compare contains-relations surrounding <- attr(bndGermany, "surrounding") whichInner <- which(sapply(surrounding, length) > 0L) bndContainsData <- data.frame(inner=names(bndGermany)[whichInner], outer=unlist(surrounding)) surrounding <- attr(germany, "surrounding") whichInner <- which(sapply(surrounding, length) > 0L) originalContainsData <- data.frame(inner=names(germany)[whichInner], outer=unlist(surrounding)) stopifnot(all(bndContainsData[order(bndContainsData$inner), ] == originalContainsData[order(originalContainsData$inner), ])) ## End(Not run)
Computes and plot autocorrelation functions for samples obtained with MCMC in BayesX
plotautocor(data, ask = TRUE, lag.max=100, ...)
plotautocor(data, ask = TRUE, lag.max=100, ...)
data |
Either the name of a file or a data frame containing the sample. |
ask |
|
lag.max |
Maximum number of lags to be considered. |
... |
Further parameters to be passed to the internal call of |
Felix Heinzl, Thomas Kneib
res <- read.table(system.file("examples/nonparametric_f_x_pspline_sample.raw", package="BayesX"), header=TRUE) plotautocor(res) plotautocor(res, lag.max=50)
res <- read.table(system.file("examples/nonparametric_f_x_pspline_sample.raw", package="BayesX"), header=TRUE) plotautocor(res) plotautocor(res, lag.max=50)
Plots nonparametric function estimates obtained from BayesX
plotnonp(data, x = 2, y = c(3, 4, 5, 7, 8), ylim = NULL, lty = c(1, 2, 3, 2, 3), cols = rep(1, length(y)), month, year, step=12, xlab, ylab, ...)
plotnonp(data, x = 2, y = c(3, 4, 5, 7, 8), ylim = NULL, lty = c(1, 2, 3, 2, 3), cols = rep(1, length(y)), month, year, step=12, xlab, ylab, ...)
data |
Either the name of a file or a data frame containing the estimation results. |
x |
Defines the x-axis in the plot. Either the name of a variable in |
y |
Defines the variables to be plotted against |
ylim |
Since |
lty |
Vector of line types used for plotting (must have the same length as |
cols |
Vector of colors used for plotting (must have the same length as |
month , year , step
|
Provide specific annotation for plotting estimation results for temporal variables. |
xlab , ylab
|
|
... |
Further arguments to be passed to the interval call of |
Felix Heinzl, Andreas Brezger and Thomas Kneib
drawmap
,plotautocor
,plotsample
,plotsurf
res <- read.table(system.file("examples/nonparametric_f_x_pspline.res", package="BayesX"), header=TRUE) plotnonp(res) plotnonp(res, x="x") plotnonp(res, x="x", y="pmean") plotnonp(res, x="x", y="pmed") plotnonp(res, x="x", y="pmed", ylim=c(-2,2)) plotnonp(res, x="x", y=c("pmean", "pqu10", "pqu90"), lty=c(1,1,1), col=c("red","blue","blue")) plotnonp(res, xlab="some variable", ylab="f(some variable)", main="Nonlinear effect of some variable", sub="penalised spline") res <- read.table(system.file("examples/nonparametric2_f_time_pspline.res", package="BayesX"), header=TRUE) plotnonp(res) plotnonp(res, month=1, year=1980, step=12) res <- res[1:18,] plotnonp(res, month=1, year=1980, step=12)
res <- read.table(system.file("examples/nonparametric_f_x_pspline.res", package="BayesX"), header=TRUE) plotnonp(res) plotnonp(res, x="x") plotnonp(res, x="x", y="pmean") plotnonp(res, x="x", y="pmed") plotnonp(res, x="x", y="pmed", ylim=c(-2,2)) plotnonp(res, x="x", y=c("pmean", "pqu10", "pqu90"), lty=c(1,1,1), col=c("red","blue","blue")) plotnonp(res, xlab="some variable", ylab="f(some variable)", main="Nonlinear effect of some variable", sub="penalised spline") res <- read.table(system.file("examples/nonparametric2_f_time_pspline.res", package="BayesX"), header=TRUE) plotnonp(res) plotnonp(res, month=1, year=1980, step=12) res <- res[1:18,] plotnonp(res, month=1, year=1980, step=12)
Plots sampling paths obtained with MCMC-sampling in BayesX
plotsample(data, ask = TRUE, ...) plotsample.coda(data, ask = TRUE, ...)
plotsample(data, ask = TRUE, ...) plotsample.coda(data, ask = TRUE, ...)
data |
Either the name of a file or a data frame containing the sample. |
ask |
|
... |
Further parameters to be passed to the internal call of |
plotsample
simply plots sampling paths while plotsampe.coda
makes use of the plotting facilities available in package coda
.
Felix Heinzl, Andreas Brezger, Thomas Kneib
drawmap
,plotautocor
,plotnonp
,plotsurf
,
res <- read.table(system.file("examples/nonparametric_f_x_pspline_sample.raw", package="BayesX"), header=TRUE) plotsample(res)
res <- read.table(system.file("examples/nonparametric_f_x_pspline_sample.raw", package="BayesX"), header=TRUE) plotsample(res)
Visualises surface estimates obtained with BayesX.
plotsurf(data, x=2, y=3, z=4, mode=1, ticktype="detailed", expand=0.75, d=100, theta=-30, phi=25, ...)
plotsurf(data, x=2, y=3, z=4, mode=1, ticktype="detailed", expand=0.75, d=100, theta=-30, phi=25, ...)
data |
Either the name of a file or a data frame containing the estimation results. |
x |
Defines the x-axis in the plot. Either the name of a variable in |
y |
Defines the y-axis in the plot. Either the name of a variable in |
z |
Defines the z-axis in the plot. Either the name of a variable in |
mode |
|
ticktype , expand , d , theta , phi
|
Overwrite the default behaviour of |
... |
Further parameteres that are parsed to the internal call to |
Felix Heinzl, Thomas Kneib
drawmap
,plotautocor
,plotsample
,plotnonp
res <- read.table(system.file("examples/surface_f_x1_x2_pspline.res", package="BayesX"), header=TRUE) plotsurf(res) plotsurf(res, mode=2) plotsurf(res, mode=3) plotsurf(res, x="x1", y="x2", z="pmed") plotsurf(res, ticktype="simple") plotsurf(res, main="3D-Plot", xlab="myx", ylab="myy", zlab="f(myx,myy)")
res <- read.table(system.file("examples/surface_f_x1_x2_pspline.res", package="BayesX"), header=TRUE) plotsurf(res) plotsurf(res, mode=2) plotsurf(res, mode=3) plotsurf(res, x="x1", y="x2", z="pmed") plotsurf(res, ticktype="simple") plotsurf(res, main="3D-Plot", xlab="myx", ylab="myy", zlab="f(myx,myy)")
Reads the geographical information provided in a file in boundary format (see Ch. 5 of the BayesX Reference Manual) and stores it in a map object.
read.bnd(file, sorted=FALSE)
read.bnd(file, sorted=FALSE)
file |
Name of the boundary file to be read. |
sorted |
Should the regions be ordered by the numbers speciying the region names ( |
Returns a list of polygons that form the map. Additional attributes are
surrounding |
Parallel list where for each polygon, the name of a possible surrounding region is saved. |
height2width |
Ratio between height and width of the map. Allows customised drawing and storage in files by specifying the appropriate height and width. |
class |
Indicates whether the map is stored in boundary format ( |
Daniel Sabanes Bove, Felix Heinzl, Thomas Kneib, Andreas Brezger
BayesX Reference Manual. Available from https://www.uni-goettingen.de/de/bayesx/550513.html
write.bnd
,drawmap
,read.gra
,write.gra
germany <- read.bnd(system.file("examples/germany.bnd", package="BayesX")) drawmap(map=germany) attributes(germany) germany <- read.bnd(system.file("examples/germany2001.bnd", package="BayesX")) drawmap(map=germany) attributes(germany)
germany <- read.bnd(system.file("examples/germany.bnd", package="BayesX")) drawmap(map=germany) attributes(germany) germany <- read.bnd(system.file("examples/germany2001.bnd", package="BayesX")) drawmap(map=germany) attributes(germany)
Reads the geographical information provided in a file in graph format (see Ch. 5 of the BayesX Reference Manual) and stores it in a map object.
read.gra(file, sorted=FALSE)
read.gra(file, sorted=FALSE)
file |
Name of the graph file to be read. |
sorted |
Should the regions be ordered by the numbers speciying the region names ( |
Returns an adjacency matrix that represents the neighborhood structure defined in the graph file. Additional attributes are
dim |
Dimension of the (square) adjacency matrix. |
dimnames |
List of region names corresponding to rows and columns of the adjacency matrix. |
class |
Indicates whether the map is stored in boundary format ( |
Thomas Kneib, Felix Heinzl
BayesX Reference Manual. Available from https://www.uni-goettingen.de/de/bayesx/550513.html
write.gra
,read.bnd
,write.bnd
,get.neighbor
,add.neighbor
,delete.neighbor
germany <- read.gra(system.file("examples/germany.gra", package="BayesX")) attributes(germany)
germany <- read.gra(system.file("examples/germany.gra", package="BayesX")) attributes(germany)
Converts the geographical information provided in a shape-file into a boundary object (see Ch. 5 of the Reference Manual)
shp2bnd(shpname, regionnames, check.is.in = TRUE)
shp2bnd(shpname, regionnames, check.is.in = TRUE)
shpname |
Base filename of the shape-file (including path) |
regionnames |
Either a vector of region names or the name of the variable in the dbf-file representing these names |
check.is.in |
Test whether some regions are surrounded by other regions (FALSE speeds up the execution time but may result in a corrupted bnd-file) |
Returns a boundary object, i.e. a list of polygons that form the
map. See read.bnd
for more information on the format.
Felix Heinzl, Daniel Sabanes Bove, Thomas Kneib with contributions by Michael Hoehle and Frank Sagerer
BayesX Reference Manual. Available from https://www.uni-goettingen.de/de/bayesx/550513.html
## read shapefile into bnd object shpName <- sub(pattern="(.*)\\.dbf", replacement="\\1", x=system.file("examples/northamerica_adm0.dbf", package="BayesX")) north <- shp2bnd(shpname=shpName, regionnames="COUNTRY") ## draw the map drawmap(map=north) ## compare with shipped bnd file shippedBnd <- read.bnd(system.file("examples/northamerica.bnd", package="BayesX")) stopifnot(all.equal(north, shippedBnd))
## read shapefile into bnd object shpName <- sub(pattern="(.*)\\.dbf", replacement="\\1", x=system.file("examples/northamerica_adm0.dbf", package="BayesX")) north <- shp2bnd(shpname=shpName, regionnames="COUNTRY") ## draw the map drawmap(map=north) ## compare with shipped bnd file shippedBnd <- read.bnd(system.file("examples/northamerica.bnd", package="BayesX")) stopifnot(all.equal(north, shippedBnd))
Rounds the boundary information in a map object in boundary format to a specified precision.
smooth.bnd(map, digits = 2, scale = 1)
smooth.bnd(map, digits = 2, scale = 1)
map |
Map object in boundary format that should be modified. |
digits |
Number of digits to round to. |
scale |
Scaling factor that should be applied for rounding. For example, with
|
Map object in boundary format rounded to the specified precision.
Felix Heinzl, Thomas Kneib
Writes the information of a map object to a file (in boundary format)
write.bnd(map, file, replace = FALSE)
write.bnd(map, file, replace = FALSE)
map |
Map object ot be saved (should be in boundary format). |
file |
Name of the file to write to |
replace |
Should an existing file be overwritten with the new version? |
Thomas Kneib, Felix Heinzl
BayesX Reference Manual. Available from https://www.uni-goettingen.de/de/bayesx/550513.html
Writes the information of a map object to a file (in graph format)
write.gra(map, file, replace = FALSE)
write.gra(map, file, replace = FALSE)
map |
Map object ot be saved (should be in graph format, see |
file |
Name of the file to write to |
replace |
Should an existing file be overwritten with the new version? |
Thomas Kneib, Felix Heinzl
BayesX Reference Manual. Available from https://www.uni-goettingen.de/de/bayesx/550513.html