Search code examples
rpolygonspatial

How to assign individuals in the same Census tract to different spatial points in R?


I'm working with confidential survey data that contain each respondent's Census tract (but nothing below that). There are ~6 respondents per Census tract, and about 2,000 distinct Census tracts in the data.

I ran a logistic regression model using respondent-level variables to predict whether the respondent has ever been diagnosed with asthma. I wanted to map the residuals, to examine any potential spatial clusters or patterns, but don't know how to proceed when my unit of analysis = individuals who share the same location (tract) as others in the data.

Can I convert each respondent's location from the Census tract to a unique spatial point within the Census tract? I.e., can I assign a unique spatial point to each respondent within the same Census tract (at random)? Or is there another way to go about this?

Would love any feedback! (Note: I'm currently working with a Spatial Polygons Dataframe in R.)


Solution

  • I was able to do this using @mrhellmann's advice. I used the steps outlined on this site to accomplish this: https://rstudio-pubs-static.s3.amazonaws.com/200263_e77d00d6b6b24aa8890c8c4f074bcdff.html

    The only thing I added at the end was to merge my points data points with my actual data frame df:

    points.df <- SpatialPointsDataFrame(points, data = df)
    

    I then plotted the residuals using the following code, where sp is my Spatial Polygons data frame:

    plot(sp, main= "Residuals"); points(points.df, col= points.df$poly_id, pch= 1, cex= points.df$residuals)