The ssn_get_data
function extracts an
sf data.frame for the observation or prediction data from
an SSN
, ssn_lm
, or ssn_glm
object.
Arguments
- x
An object of class
SSN
,ssn_lm
, orssn_glm
.- name
the internal name of the dataset in the object
x
. For observed values, this will always be "obs", the default.
Details
The internal name
for observed data in objects of
class SSN
is "obs" and it is the
default. If another name
is specified, it must represent a
prediction data set in the SSN
,
ssn_lm
, or ssn_glm
object. For SSN
objects,
these names are obtained using the call names(x$preds)
. For
all other object classes, the names are obtained using the call
names(x$ssn.object$preds)
.
Examples
## Extract observed data from an SSN object
# Copy the mf04p .ssn data to a local directory and read it into R
# When modeling with your .ssn object, you will load it using the relevant
# path to the .ssn data on your machine
copy_lsn_to_temp()
temp_path <- paste0(tempdir(), "/MiddleFork04.ssn")
mf04p <- ssn_import(temp_path, predpts = "pred1km", overwrite = TRUE)
obs.df <- ssn_get_data(mf04p)
dim(obs.df)
#> [1] 45 26
## Extract prediction data from an SSN object
names(mf04p$preds)
#> [1] "pred1km"
pred1km.df <- ssn_get_data(mf04p, name = "pred1km")
names(pred1km.df)
#> [1] "COMID" "GNIS_NAME" "CDRAINAG" "AREAWTMAP" "SLOPE"
#> [6] "ELEV_DEM" "FlowCMS" "AirMEANc" "AirMWMTc" "NEAR_X"
#> [11] "NEAR_Y" "rid" "ratio" "afvArea" "upDist"
#> [16] "locID" "netID" "pid" "geometry" "netgeometry"
## extract observed data from an ssn_lm object
ssn_mod <- ssn_lm(
formula = Summer_mn ~ ELEV_DEM,
ssn.object = mf04p,
tailup_type = "exponential",
additive = "afvArea"
)
obs.mod.df <- ssn_get_data(ssn_mod)
summary(obs.mod.df)
#> STREAMNAME COMID CDRAINAG AREAWTMAP
#> Length:45 Min. :23519297 Min. : 8.643 Min. : 786.4
#> Class :character 1st Qu.:23519365 1st Qu.: 60.136 1st Qu.: 968.2
#> Mode :character Median :23519479 Median : 93.295 Median : 995.2
#> Mean :23519557 Mean :136.482 Mean : 998.6
#> 3rd Qu.:23519529 3rd Qu.:171.534 3rd Qu.:1032.7
#> Max. :23522805 Max. :477.696 Max. :1130.4
#> SLOPE ELEV_DEM Source Summer_mn
#> Min. :0.000000 Min. :1923 Length:45 Min. : 8.75
#> 1st Qu.:0.002740 1st Qu.:1952 Class :character 1st Qu.:11.02
#> Median :0.005680 Median :2006 Mode :character Median :12.06
#> Mean :0.006743 Mean :1999 Mean :12.35
#> 3rd Qu.:0.008430 3rd Qu.:2026 3rd Qu.:14.58
#> Max. :0.044260 Max. :2085 Max. :15.29
#> MaxOver20 C16 C20 C24 FlowCMS
#> Min. :0.0000 Min. : 0.0 Min. : 0.000 Min. :0 Min. :28.67
#> 1st Qu.:0.0000 1st Qu.:17.0 1st Qu.: 0.000 1st Qu.:0 1st Qu.:28.67
#> Median :0.0000 Median :32.0 Median : 0.000 Median :0 Median :28.67
#> Mean :0.3111 Mean :26.4 Mean : 2.867 Mean :0 Mean :28.67
#> 3rd Qu.:1.0000 3rd Qu.:39.0 3rd Qu.: 3.000 3rd Qu.:0 3rd Qu.:28.67
#> Max. :1.0000 Max. :41.0 Max. :19.000 Max. :0 Max. :28.67
#> AirMEANc AirMWMTc NEAR_X NEAR_Y
#> Min. :21.12 Min. :35.1 Min. :-1530805 Min. :2527111
#> 1st Qu.:21.12 1st Qu.:35.1 1st Qu.:-1520336 1st Qu.:2529903
#> Median :21.12 Median :35.1 Median :-1512691 Median :2533285
#> Mean :21.12 Mean :35.1 Mean :-1514996 Mean :2532817
#> 3rd Qu.:21.12 3rd Qu.:35.1 3rd Qu.:-1508544 3rd Qu.:2535462
#> Max. :21.12 Max. :35.1 Max. :-1503079 Max. :2537823
#> rid ratio afvArea upDist
#> Min. : 0.00 Min. :0.0143 Length:45 Min. : 909.9
#> 1st Qu.: 20.00 1st Qu.:0.1967 Class :character 1st Qu.: 6281.2
#> Median : 41.00 Median :0.4720 Mode :character Median :10020.0
#> Mean : 41.27 Mean :0.4564 Mean :10176.7
#> 3rd Qu.: 60.00 3rd Qu.:0.6936 3rd Qu.:14295.2
#> Max. :109.00 Max. :0.9739 Max. :19566.2
#> locID netID pid geometry
#> Min. : 1 Min. :1.000 Min. : 1 POINT :45
#> 1st Qu.:12 1st Qu.:1.000 1st Qu.:12 epsg:NA : 0
#> Median :23 Median :2.000 Median :23 +proj=aea ...: 0
#> Mean :23 Mean :1.711 Mean :23
#> 3rd Qu.:34 3rd Qu.:2.000 3rd Qu.:34
#> Max. :45 Max. :2.000 Max. :45
#> netgeometry
#> Length:45
#> Class :character
#> Mode :character
#>
#>
#>