Skip to contents

Augment dataframe with predictions of model

Usage

st_augment(model, df)

Arguments

model

an `mgcv`, `lme4` or `nlme` model.

df

an `sf` data frame to be augmented with model predictions.

Value

An augmented `sf` data frame with extra columns showing estimates of random effects from model.

Examples

prepdata <- st_bridges(uk_election,"constituency_name")
mgcv::gam(health_not_good ~
  s(constituency_name, bs='mrf', xt=list(nb=prepdata$nb), k=100),
  data=prepdata, method="REML") |>
st_augment(uk_election)
#> Simple feature collection with 632 features and 10 fields
#> Geometry type: GEOMETRY
#> Dimension:     XY
#> Bounding box:  xmin: 5513.182 ymin: 7057.949 xmax: 655655.4 ymax: 1218620
#> Projected CRS: OSGB36 / British National Grid
#> First 10 features:
#>    degree_educated health_not_good      white  con_swing population
#> 1      -1.21794372       2.4694480  0.6393329  8.5917223      66133
#> 2       0.04609836       0.5666903  0.6561204  2.2040312      56415
#> 3       0.26593462      -0.8699365  0.1441816  7.1285493      99654
#> 4       1.62837520      -1.7731408  0.3038995  2.9732599      93197
#> 5      -1.35386780       0.8155333  0.6963927 -0.2362672      85845
#> 6      -0.21109416      -1.3619136 -0.1675498  5.6993250     103922
#> 7      -0.74760203       0.8047040  0.3409127  7.4304029      76974
#> 8       1.63438559      -1.1613230  0.1605045 -0.4813182      96591
#> 9      -0.65926781      -0.1982048  0.6815335  5.6002269      82505
#> 10     -0.96445730       0.9975218  0.6930268  9.4698002      87883
#>           region             county        constituency_name  mrf.smooth
#> 1          Wales     West Glamorgan                 Aberavon  1.82293254
#> 2          Wales              Clwyd                Aberconwy  0.48444472
#> 3       Scotland           Scotland           Aberdeen North -1.58021815
#> 4       Scotland           Scotland           Aberdeen South -1.70435245
#> 5       Scotland           Scotland       Airdrie and Shotts  0.07320101
#> 6     South East          Hampshire                Aldershot -1.51043755
#> 7  West Midlands      West Midlands      Aldridge-Brownhills  0.63368847
#> 8     North West Greater Manchester Altrincham and Sale West  0.03473148
#> 9          Wales              Clwyd         Alyn and Deeside  0.14602595
#> 10 East Midlands         Derbyshire             Amber Valley  0.52999669
#>    se.mrf.smooth                       geometry
#> 1      0.1944985 POLYGON ((290786.3 202886.7...
#> 2      0.2178170 POLYGON ((283209.3 381440.5...
#> 3      0.2909148 MULTIPOLYGON (((395379.7 80...
#> 4      0.3990368 POLYGON ((396214 805849.7, ...
#> 5      0.1670717 POLYGON ((290854.4 662154.9...
#> 6      0.1735666 POLYGON ((485408.1 159918.6...
#> 7      0.1068069 POLYGON ((406519.5 305056.1...
#> 8      0.1541860 POLYGON ((379104.1 393145.7...
#> 9      0.1869323 POLYGON ((331643.4 372873.5...
#> 10     0.1284806 POLYGON ((444868.5 353960.2...