Package seg February 15, 2013 Version 0.2-4 Date 2013-01-21 Title A set of tools for residential segregation research Author Seong-Yun Hong, David O Sullivan Maintainer Seong-Yun Hong <hong.seongyun@gmail.com> Depends R (>= 2.10.0), methods, sp, spatstat (>= 1.27.0), raster (>= 1.9.92) Suggests spdep A package that provides functions to measure the overall degree of residential segregation. The methods implemented in this package include Duncan and Duncan s index of dissimilarity (1955), Morrill (1991) and Wong (1993) s adjusted indices of dissimilarity, White s spatial segregation measure (1983), and Reardon and O Sullivan s spatial segregation measures (2004). License GPL (>= 2) URL https://sites.google.com/site/hongseongyun/seg LazyLoad Yes Collate SegLocalEnv-class.R SegLocalEnv.R SegLocalEnv-methods.R getseglocalenv.r SegSpatial-class.R SegSpatial-methods.R SegSpatial.R SegSpatialExt-class.R SegSpatialExt-methods.R spseg.r seg.r whiteseg.r Repository CRAN Date/Publication 2013-01-21 07:45:54 NeedsCompilation yes 1
2 getseglocalenv R topics documented: getseglocalenv....................................... 2 seg.............................................. 4 segdata........................................... 6 SegLocalEnv........................................ 7 SegLocalEnv-class..................................... 8 SegSpatial-class....................................... 9 spseg............................................ 10 update............................................ 12 whiteseg........................................... 13 Index 16 getseglocalenv Calculate Local Environment Parameters Calculate the population composition of the local environment at each data point from a matrix of coordinates, or an object of class Spatial or ppp. Usage getseglocalenv(x, data, power = 2, useexp = TRUE, maxdist, sprel, error =.Machine$double.eps) Arguments x data power useexp maxdist sprel error a numeric matrix or data frame with coordinates (each row is a point), or an object of class Spatial or ppp. an object of class matrix, or one that can be coerced to that class. The number of rows in data should equal the number of points in x, and the number of columns should be greater than one (at least two population groups are required). This can be missing if x has a data frame attached to it. a numeric value that determines the change rate of a distance weight function. If zero, all data points have the same weight regardless of the distance. Typically 1-5. logical. If FALSE, use a simple inverse distance function instead of a negative exponential function. See Details. an optional numeric value specifying a search radius for the construction of each local environment. Must be a positive value, or zero. an optional object of class dist or nb. See Details. a numeric value. If useexp = FALSE, this value will be added to the denominator to prevent dividing by zero.
getseglocalenv 3 Details The local environment parameters are the weighted averages of the populations of all points within a search radius maxdist and are an essential component for calculation of the spatial segregation measures. By default, the weight of each point is calculated from a negative exponential function, which is defined as: w(d) = e d power where d is the Euclidean distance between two points. If useexp is FALSE, a simple inverse distance function is used to calculate the weight of each point: w(d) = 1 (d + error) power If maxdist is not provided (default), all data points in the study area are used for the construction of each local environment. It is recommended to specify this parameter to speed up the calculation process. If a distance measure other than the Euclidean distance is required to represent spatial proximity between the points, the users can provide an object of class dist, which contains the distances between all pairs of the points, through an optional argument sprel. One convenient way of obtaining such information may be the use of the function dist, which offers a variety of distance measures, such as Manhattan, Canberra, and Minkowski. Or alternatively, one can supply an object of class nb to use a k-nearest neighbour averaging or polygon contiguity. Value An object of class LocalEnv. Note Note that this function is not to interpolate between data points. The calculation of each local environment involves the point itself, so the simple inverse distance function with a power of 2 or more should be used with care. Author(s) Seong-Yun Hong See Also SegLocalEnv, SegLocalEnv-class, spseg, dist
4 seg Examples # Create a random data set with 50 data points and 3 population groups xy <- matrix(runif(100), ncol = 2) pop <- matrix(runif(150), ncol = 3) env1 <- getseglocalenv(xy, pop) summary(env1) xy.dist <- dist(xy, method = "manhattan") maxdist <- quantile(as.matrix(xy), 0.75) env2 <- getseglocalenv(xy, pop, maxdist = maxdist, sprel = xy.dist) summary(env2) env3 <- getseglocalenv(xy, pop, useexp = FALSE, power = 0, maxdist = 0.5) summary(env3) env4 <- getseglocalenv(xy, pop, useexp = FALSE, maxdist = 0.5) summary(env4) seg Calculate Index of Dissimilarity seg calculates Duncan and Duncan s index of dissimilarity between two population groups. If nb is given, the index can be adjusted to reflect the spatial distribution of population. Usage seg(data, nb, verbose = FALSE) Arguments data nb verbose a numeric matrix or data frame with two columns that represent mutually exclusive population groups (e.g., Asians and non-asians). If more than two columns are given, only the first two will be used for computing the index. an optional matrix object describing the intensity of interaction between geographic units. logical. If TRUE, print the current stage of the computation and time spent on each job to the screen. Details nb must be a square matrix (same number of rows and columns) but does not have to be symmetric. When nb is not specified, seg calculates the traditional index of dissimilarity proposed by Duncan and Duncan (1955).
seg 5 Value If nb is a rook-based contiguity matrix standardised by the total number of neighbours, the calculation follows the Morrill s adjusted index of dissimilarity (1991). See the example code below and help(nb2mat) for more information regarding how to construct such a matrix. If nb contains row-standardised shared boundary lengths between geographic units, the computed index is Wong s adjusted D. In R, vect2neigh in the spgrass6 package can be used to obtain the shared boundary lengths. A single numeric value between 0 and 1, indicating the degree of segregation; 0 for no segregation, and 1 for complete segregation. Author(s) Seong-Yun Hong References Duncan, O. D., & Duncan, B. (1955). A methodological analysis of segregation indexes. American Sociological Review, 20, 210-217. Morrill, R. L. (1991). On the measure of geographic segregation. Geography Research Forum, 11, 25-36. See Also Wong, D. W. S. (1993). Spatial indices of segregation. Urban Studies, 30, 559-572. spseg, whiteseg Examples if (require(spdep)) { data(segdata) segdata.df <- data.frame(segdata) segdata.nb <- nb2mat(poly2nb(segdata, queen = FALSE), style = "B") segdata.nb <- segdata.nb / sum(segdata.nb) dd <- numeric(); dm <- numeric() pd <- par() par(mfrow = c(2, 4), mar = c(0, 1, 0, 1)) for (i in 1:8) { idx <- 2 * i dd <- append(dd, seg(segdata.df[,(idx-1):idx])) dm <- append(dm, seg(segdata.df[,(idx-1):idx], segdata.nb)) full <- segdata.df[,(idx-1)] == 100 half <- segdata.df[,(idx-1)] == 50 plot(segdata) plot(segdata[full,], col = "Black", add = TRUE) if (any(half)) plot(segdata[half,], col = "Grey", add = TRUE) text(5, 11.5, labels = paste("d = ", round(dd[i], 2), ", D(adj) = ", round(dm[i], 2), sep = ""))
6 segdata } } segdata Hypothetical Patterns of Segregation Usage Format This data set contains eight different spatial configurations that were used by Morrill (1991) and Wong (1993) to test their segregation measures. data(segdata) A class of SpatialPolygonsDataFrame. The data slot contains 16 columns, representing eight idealised spatial patterns. Each column indicates the following information: [,1] A1 Pattern A, Group 1 [,2] A2 Pattern A, Group 2 [,3] B1 Pattern B, Group 1 [,4] B2 Pattern B, Group 2 [,5] C1 Pattern C, Group 1 [,6] C2 Pattern C, Group 2 [,7] D1 Pattern D, Group 1 [,8] D2 Pattern D, Group 2 [,9] E1 Pattern E, Group 1 [,10] E2 Pattern E, Group 2 [,11] F1 Pattern F, Group 1 [,12] F2 Pattern F, Group 2 [,13] G1 Pattern G, Group 1 [,14] G2 Pattern G, Group 2 [,15] H1 Pattern H, Group 1 [,16] H2 Pattern H, Group 2 Source Morrill, R. L. (1991). On the measure of geographic segregation. Geography Research Forum, 11, 25-36. Wong, D. W. S. (1993). Spatial Indices of Segregation. Urban Studies, 30, 559-572. Examples data(segdata) par(mfrow = c(2, 4), mar = c(0, 1, 0, 1))
SegLocalEnv 7 for (i in 1:8) { full <- data.frame(segdata)[,(2 * i)-1] == 100 half <- data.frame(segdata)[,(2 * i)-1] == 50 plot(segdata) plot(segdata[full,], col = "Black", add = TRUE) if (any(half)) plot(segdata[half,], col = "Grey", add = TRUE) text(5, 11.5, labels = paste("pattern", LETTERS[i])) } SegLocalEnv Create an Object of Class SegLocalEnv Create a new object of class SegLocalEnv from a matrix of coordinates and population data. Usage SegLocalEnv(coords, data, env, proj4string = CRS(as.character(NA))) Arguments coords data env proj4string a numeric matrix or data frame with coordinates (each row is a point). an object of class matrix containing the population of each group at each data point. The number of rows in data should equal the number of points in coords, and the number of columns should be greater than one (at least two population groups are required). an optional object of class matrix containing the local environment parameters. Must be the same dimensions as data. If missing, use data. an optional projection string of class CRS. Value An object of class SegLocalEnv. Author(s) Seong-Yun Hong See Also getseglocalenv, update.seglocalenv, spseg, SegLocalEnv-class Examples # Create a random data set with 50 data points and 3 population groups xy <- matrix(runif(100), ncol = 2) pop <- matrix(runif(150), ncol = 3) localenv <- SegLocalEnv(coords = xy, data = pop)
8 SegLocalEnv-class SegLocalEnv-class Class SegLocalEnv Class for local environments of spatial data points. Objects from the Class Slots Objects can be created by the function SegLocalEnv. coords an object of class matrix, containing the coordinates (each row is a point). data an object of class matrix, containing the population composition at each point (each column is a population group). env an object of class matrix, containing the population composition of the local environment for each point. proj4string an object of class CRS, projection string. Methods coerce signature(from = "SegLocalEnv", to = "list"): coerce an object of class SegLocalEnv to an object of class list. coerce signature(from = "SegLocalEnv", to = "SpatialPointsDataFrame"): coerce an object of class SegLocalEnv to an object of class SpatialPointsDataFrame. coerce signature(from = "list", to = "SegLocalEnv"): coerce an object of class list to an object of class SegLocalEnv. coerce signature(from = "SpatialPointsDataFrame", to = "SegLocalEnv"): coerce an object of class SpatialPointsDataFrame to an object of class SegLocalEnv. coerce signature(from = "SpatialPolygonsDataFrame", to = "SegLocalEnv"): coerce an object of class SpatialPolygonsDataFrame to an object of class SegLocalEnv. as.list signature(x = "SegLocalEnv"): coerce an object of class SegLocalEnv to an object of class list. show signature(object = "SegLocalEnv"): show the number of points and data columns in an object of class SegLocalEnv. print signature(x = "SegLocalEnv"): same as show. summary signature(object = "SegLocalEnv"): summarise the population compositions of points and local environments in an object of class SegLocalEnv. plot signature(x = "SegLocalEnv"): draw a plot, or plots, of points in an object of class SegLocalEnv. Use an optional argument which.col to specify a column of the data that determines the points sizes. See Examples below for demonstration. points signature(x = "SegLocalEnv"): draw points in an object of class SegLocalEnv on an active graphic device.
SegSpatial-class 9 Author(s) Seong-Yun Hong See Also SegLocalEnv, getseglocalenv, update Examples # Create a random data set with 50 data points and 3 population groups xy <- matrix(runif(100), ncol = 2) pop <- matrix(runif(150), ncol = 3) localenv <- SegLocalEnv(coords = xy, data = pop) # Generic functions print(localenv) summary(localenv) par(mfrow = c(1, 3)) plot(localenv, xlab = "x", ylab = "y") par(mfrow = c(1, 2)) plot(localenv, xlab = "x", ylab = "y", which.col = c(1, 3)) as.list(localenv) SegSpatial-class Class SegSpatial Class for spatial segregation index values. Objects from the Class Objects can be created by the function spseg, or SegSpatial. Slots d an object of class numeric, indicating the degree of the spatial dissimilarity index. r an object of class numeric, indicating the degree of the spatial diversity index. h an object of class numeric, indicating the degree of the spatial information theory index. p an object of class matrix, showing the spatial exposure/isolation of all population groups.
10 spseg Methods coerce signature(from = "SegSpatial", to = "list"): coerce an object of class SegSpatial to an object of class list. coerce signature(from = "list", to = "SegSpatial"): coerce an object of class list to an object of class SegSpatial. as.list signature(x = "SegSpatial"): coerce an object of class SegSpatial to an object of class list. show signature(object = "SegSpatial"): print the spatial segregation values. print signature(x = "SegSpatial"): same as show. Author(s) See Also Seong-Yun Hong spseg spseg Calculate Spatial Segregation Measures Usage Calculate Reardon and O Sullivan s four spatial segregation measures. spseg(x, data, method = "all", smoothing = "none", nrow = 100, ncol = 100, window, sigma, usec = TRUE, negative.rm = FALSE, tol =.Machine$double.eps, verbose = FALSE,...) SegSpatial(env, method = "all", usec = TRUE, negative.rm = FALSE, tol =.Machine$double.eps) Arguments x env data method a numeric matrix or data frame with coordinates (each row is a point), or an object of class Spatial or ppp. an object of class SegLocalEnv. an object of class matrix, or one that can be coerced to that class. The number of rows in data should equal the number of points in x, and the number of columns should be greater than one (at least two population groups are required). This can be missing if x has a data frame attached to it. a vector of character strings indicating an measure or measures to be computed. This must be one or more of the strings "all" (default), "exposure", "information", "diversity", and "dissimilarity". Abbreviations are accepted, as long as it is clear which method is meant.
spseg 11 smoothing nrow ncol window sigma a character string indicating a smoothing method. This must be (an abbreviation of) one of the strings "none" (default), "kernel", or "equal". an optional numeric value indicating the number of row cells in the rasterised data surface. Ignored if smoothing = "none". an optional numeric value indicating the number of column cells. an optional object of class owin to be passed to smooth.ppp. See Details. an optional numeric value specifying standard deviation of isotropic Gaussian smoothing kernel to be passed to density.ppp. See also Details. usec logical. If TRUE, calculate the segregation values in C. negative.rm tol Details Value verbose logical. If TRUE, all geographic units where at least one group (i.e., column) has a population of zero or less will be removed to prevent -Inf or NaN in the information theory index. If FALSE, the non-positive values will be replaced with tol. the tolerance for detecting differences between values. Differences in the input values that are smaller than tol should make no changes in the output index values. The default is.machine$double.eps. See help(.machine) for definition. logical. If TRUE, print the current stage of the computation and time spent on each job to the screen.... optional arguments to be passed to getlocalenv to compute the population composition of each local environment. SegSpatial computes the set of spatial segregation measures proposed by Reardon and O Sullivan. spseg is a wrapper function, which calls SegSpatial after constructing a population density surface and its local environment parameters with user-specified options. Currently the population density surface is estimated using the rasterize function in the raster package if the population density is assumed to be uniform in each census tract, or using density.ppp in the spatstat package if the kernel density estimation is to be used. The local environment parameters are calculated based on the output surface using getseglocalenv. An object of class SegSpatialExt. Note The exposure/isolation index, P, is presented in a matrix form. The spatial exposure of group m to group n is located in the row m and column n of the matrix. The matrix is rarely symmetric in practice so the spatial exposure index should be interpreted with care. The spatial isolation index values are given in the diagonal cells of the matrix; cell value at (m, m) indicates the degree of spatial isolation for group m for example. Author(s) Seong-Yun Hong
12 update References Reardon, S. F. and O Sullivan, D. (2004) Measures of spatial segregation. Sociological Methodology, 34, 121-162. Reardon, S. F., Farrell, C. R., Matthews, S. A., O Sullivan, D., Bischoff, K., and Firebaugh, G. (2009) Race and space in the 1990s: Changes in the geographic scale of racial residential segregation, 1990-2000. Social Science Research, 38, 55-70. See Also getseglocalenv, SegSpatial-class, rasterize, density.ppp Examples # Create a random data set with 50 data points and 3 population groups xy <- matrix(runif(100), ncol = 2) pop <- matrix(runif(150), ncol = 3) rana <- spseg(xy, pop, smoothing = "kernel", maxdist = 0.5) ranb <- spseg(xy, pop, smoothing = "kernel", useexp = FALSE, power = 0, maxdist = 0.5) print(ranb, digits = 3) par(mfrow = c(1, 3), mar = c(0, 1, 0, 2.5)) plot(ranb, main = "") update Update an Object of Class SegLocalEnv Update an existing object of class SegLocalEnv. Usage ## S3 method for class SegLocalEnv update(object, coords, data, env, proj4string,...) Arguments object an object of class LocalEnv to be updated. coords an optional object of class matrix containing coordinates of the data points (each row is a point). data an optional object of class matrix containing the population of each group at each data point. The number of rows in data should equal the number of points in coords, and the number of columns should be greater than one (at least two population groups are required). env an optional object of class matrix containing the local environment parameters. Must be the same dimensions as data. proj4string an optional projection string of class CRS.... ignored.
whiteseg 13 Value An object of class SegLocalEnv. Author(s) See Also Seong-Yun Hong SegLocalEnv, getseglocalenv, SegLocalEnv-class Examples # Create a random data set with 50 data points and 3 population groups xy <- matrix(runif(100), ncol = 2) pop <- matrix(runif(150), ncol = 3) localenv <- SegLocalEnv(coords = xy, data = pop) print(localenv) # Update the projection information proj <- CRS("+proj=nzmg +datum=nzgd49") localenv2 <- update(localenv, proj4string = proj) print(localenv2) whiteseg Calculate White s Segregation Measure Usage whiteseg computes White s segregation statistic. Unlike the traditional index of dissimilarity, this is a spatial measure that takes the spatial arrangements of population into account. whiteseg(x, data, nb, method = "euclidean", p = 2, fun, verbose = FALSE) Arguments x data nb method a numeric matrix or data frame with coordinates (each row is a point), or an object of class Spatial. an object of class matrix, or one that can be coerced to that class. The number of rows in data should equal the number of geographic units in x, and the number of columns should be greater than one (at least two population groups are required). This can be missing if x has a data frame attached to it. an optional matrix object indicating the distances between the geographic units. a length-one character string indicating the distance measure to be used. This argument is passed to dist to calculate the distances between the geographic units in x. See help(dist) for available options.
14 whiteseg p fun verbose an optional argument to be passed to dist. a function for the calculation of proximity. The function should take a numeric vector as an argument (distance) and return a vector of the same length (proximity). If this is not specified, a negative exponential function is used by default. logical. If TRUE, print the current stage of the computation and time spent on each job to the screen. Details Value nb must be a square matrix (same number of rows and columns) but does not have to be symmetric. When nb is not specified, whiteseg computes the distance matrix of x using the specified optional arguments method and p. A single numeric value indicating the degree of segregation; a value of 1 indicates absence of segregation, and values greater than 1.0 indicate clustering. If the index value is less than one, it indicates an unusual form of segregation (i.e., people live closer to other population groups). Author(s) Seong-Yun Hong References White, M. J. (1983). The measurement of spatial segregation. The American Journal of Sociology, 88, 1008-1018. See Also seg, spseg, dist Examples if (require(spdep)) { data(segdata) segdata.df <- data.frame(segdata) segdata.nb <- nb2mat(poly2nb(segdata, queen = FALSE), style = "B") segdata.nb <- segdata.nb / sum(segdata.nb) d <- numeric(); p <- numeric() pd <- par() par(mfrow = c(2, 4), mar = c(0, 1, 0, 1)) for (i in 1:8) { idx <- 2 * i d <- append(d, seg(segdata.df[,(idx-1):idx], segdata.nb)) p <- append(p, whiteseg(segdata, data = segdata.df[,(idx-1):idx])) full <- segdata.df[,(idx-1)] == 100 half <- segdata.df[,(idx-1)] == 50 plot(segdata) plot(segdata[full,], col = "Black", add = TRUE) if (any(half))
whiteseg 15 plot(segdata[half,], col = "Grey", add = TRUE) text(5, 11.5, labels = paste("d = ", round(d[i], 2), ", P = ", round(p[i], 2), sep = "")) } }
Index Topic classes SegLocalEnv-class, 8 SegSpatial-class, 9 Topic datasets segdata, 6 as.list.seglocalenv-method as.list.segspatial-method as.list.segspatialext-method coerce,list,seglocalenv-method coerce,list,segspatial-method coerce,seglocalenv,list-method coerce,seglocalenv,spatialpointsdataframe-method coerce,segspatial,list-method coerce,segspatialext,list-method coerce,spatialpointsdataframe,seglocalenv-method coerce,spatialpolygonsdataframe,seglocalenv-method getseglocalenv, 2, 7, 9, 11 13 plot.seglocalenv-method plot.segspatialext-method points.seglocalenv-method print.seglocalenv-method 16 print.segspatial-method print.segspatialext-method seg, 4, 14 segdata, 6 SegLocalEnv, 3, 7, 9, 13 SegLocalEnv-class, 8 SegSpatial, 9 SegSpatial (spseg), 10 SegSpatial-class, 9 SegSpatialExt-class (SegSpatial-class), 9 show,seglocalenv-method show,segspatial-method show,segspatialext-method spseg, 3, 5, 7, 9, 10, 10, 14 summary.seglocalenv-method update, 9, 12 update.seglocalenv, 7 whiteseg, 5, 13