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.

ssn_get_data(x, name = "obs")

Arguments

x

An object of class SSN, ssn_lm, or ssn_glm.

name

the internal name of the dataset in the object x. For observed values, this will always be "obs", the default.

Value

An sf data.frame

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).

See also

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] "rid"        "pid"        "COMID"      "AREAWTMAP"  "SLOPE"     
#>  [6] "ELEV_DEM"   "FlowCMS"    "AirMEANc"   "AirMWMTc"   "rcaAreaKm2"
#> [11] "h2oAreaKm2" "ratio"      "snapdist"   "upDist"     "afvArea"   
#> [16] "locID"      "netID"      "netgeom"    "geom"      

## 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)
#>       rid              pid      STREAMNAME            COMID         
#>  Min.   :  1.00   Min.   : 1   Length:45          Min.   :23519297  
#>  1st Qu.: 21.00   1st Qu.:12   Class :character   1st Qu.:23519365  
#>  Median : 42.00   Median :23   Mode  :character   Median :23519479  
#>  Mean   : 42.27   Mean   :23                      Mean   :23519557  
#>  3rd Qu.: 61.00   3rd Qu.:34                      3rd Qu.:23519529  
#>  Max.   :110.00   Max.   :45                      Max.   :23522805  
#>    AREAWTMAP          SLOPE             ELEV_DEM       Source         
#>  Min.   : 786.4   Min.   :0.000000   Min.   :1923   Length:45         
#>  1st Qu.: 968.2   1st Qu.:0.002740   1st Qu.:1952   Class :character  
#>  Median : 995.2   Median :0.005680   Median :2006   Mode  :character  
#>  Mean   : 998.6   Mean   :0.006743   Mean   :1999                     
#>  3rd Qu.:1032.7   3rd Qu.:0.008430   3rd Qu.:2026                     
#>  Max.   :1130.4   Max.   :0.044260   Max.   :2085                     
#>    Summer_mn       MaxOver20           C16            C20              C24   
#>  Min.   : 8.75   Min.   :0.0000   Min.   : 0.0   Min.   : 0.000   Min.   :0  
#>  1st Qu.:11.02   1st Qu.:0.0000   1st Qu.:17.0   1st Qu.: 0.000   1st Qu.:0  
#>  Median :12.06   Median :0.0000   Median :32.0   Median : 0.000   Median :0  
#>  Mean   :12.35   Mean   :0.3111   Mean   :26.4   Mean   : 2.867   Mean   :0  
#>  3rd Qu.:14.58   3rd Qu.:1.0000   3rd Qu.:39.0   3rd Qu.: 3.000   3rd Qu.:0  
#>  Max.   :15.29   Max.   :1.0000   Max.   :41.0   Max.   :19.000   Max.   :0  
#>     FlowCMS         AirMEANc        AirMWMTc      rcaAreaKm2    
#>  Min.   :28.67   Min.   :21.12   Min.   :35.1   Min.   :0.0234  
#>  1st Qu.:28.67   1st Qu.:21.12   1st Qu.:35.1   1st Qu.:0.8613  
#>  Median :28.67   Median :21.12   Median :35.1   Median :2.1780  
#>  Mean   :28.67   Mean   :21.12   Mean   :35.1   Mean   :2.2958  
#>  3rd Qu.:28.67   3rd Qu.:21.12   3rd Qu.:35.1   3rd Qu.:3.3993  
#>  Max.   :28.67   Max.   :21.12   Max.   :35.1   Max.   :5.0175  
#>    h2oAreaKm2          ratio           snapdist             upDist       
#>  Min.   :  3.399   Min.   :0.0143   Min.   :0.000e+00   Min.   :  909.9  
#>  1st Qu.: 16.790   1st Qu.:0.1967   1st Qu.:0.000e+00   1st Qu.: 6281.2  
#>  Median : 29.092   Median :0.4720   Median :0.000e+00   Median :10020.0  
#>  Mean   : 36.063   Mean   :0.4565   Mean   :5.174e-12   Mean   :10176.9  
#>  3rd Qu.: 46.260   3rd Qu.:0.6936   3rd Qu.:0.000e+00   3rd Qu.:14295.2  
#>  Max.   :124.250   Max.   :0.9739   Max.   :1.164e-10   Max.   :19566.2  
#>     afvArea            locID        netID         netgeom         
#>  Min.   :0.05144   Min.   : 1   Min.   :1.000   Length:45         
#>  1st Qu.:0.15212   1st Qu.:12   1st Qu.:1.000   Class :character  
#>  Median :0.17089   Median :23   Median :2.000   Mode  :character  
#>  Mean   :0.24583   Mean   :23   Mean   :1.711                     
#>  3rd Qu.:0.29944   3rd Qu.:34   3rd Qu.:2.000                     
#>  Max.   :1.00000   Max.   :45   Max.   :2.000                     
#>           geometry 
#>  POINT        :45  
#>  epsg:NA      : 0  
#>  +proj=aea ...: 0  
#>                    
#>                    
#>