loading

Logout succeed

Logout succeed. See you again!

ebook img

Package 'SSN' PDF

pages96 Pages
release year2017
file size0.28 MB
languageEnglish

Preview Package 'SSN'

Package ‘SSN’ February9,2023 Type Package Title SpatialModelingonStreamNetworks Version 1.1.16 Date 2023-02-09 Depends R(>=4.0.0),RSQLite(>=1.1-2),sp Imports MASS,igraph(>=1.0.0),maptools,lattice,methods,Matrix, rgdal(>=1.2-5),rgeos(>=0.3-22) Maintainer JayVerHoef<[email protected]> Description Spatialstatisticalmodelingandpredictionfordataonstreamnetworks,includingmod- elsbasedonin-streamdistance(VerHoef,J.M.andPeter- son,E.E.,2010.<DOI:10.1198/jasa.2009.ap08248>.)Modelsarecreatedusingmovingaver- ageconstructions.Spatiallinearmodels,includingexplanatoryvariables,canbefitwith(re- stricted)maximumlikelihood. Mappingandothergraphicalfunctionsareincluded. License GPL-2 LazyLoad yes LinkingTo BH NeedsCompilation yes Author JayVerHoef[aut,cre], ErinPeterson[aut] Repository CRAN Date/Publication 2023-02-0920:00:06UTC R topics documented: SSN-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 additive.function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 AIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 as.SpatialLines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 binSp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 BlockPredict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 BLUP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1 2 Rtopicsdocumented: boxplot.SpatialStreamNetwork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 copyLSN2temp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 covparms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 createDistMat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 createSSN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 CrossValidationSSN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 CrossValidationStatsSSN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Designfunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 EmpiricalSemivariogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 fitNS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 fitRE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 fitSimBin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 fitSimGau . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 fitSimPoi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 fitSp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 fitSpBk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 fitSpRE1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 fitSpRE2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 getConfusionMat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 getPreds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 getSSNdata.frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 getStreamDistMat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 glmssn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 glmssn-class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 GR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 importPredpts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 importSSN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 influenceSSN-class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 InfoCritCompare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 mf04 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 mf04p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 MiddleFork04.ssn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 plot.glmssn.predict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 plot.influenceSSN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 plot.SpatialStreamNetwork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 plot.Torgegram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 poiSp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 predict.glmssn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 print.summary.glmssn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 putSSNdata.frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 residuals.glmssn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 SimulateOnSSN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 SpatialStreamNetwork-class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 splitPredictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 subsetSSN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 summary.glmssn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Torgegram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 updatePath. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 SSN-package 3 varcomp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 writeSSN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Index 95 SSN-package SpatialModelingonStreamNetworks Description CreatesspatialstreamnetworkrepresentationsinRandfitsspatialmodels. Details Package: SSN Type: Package Version: 1.1.12 Date: 2018-01-24 License: GPL-2 LazyLoad: yes The SSN package provides tools to fit generalized linear models with spatial autocorrelation for streamnetworkdata. SSNusesnormallikelihoodmethods(includingREML)andquasi-likelihood forPoissonandBinomialfamilies. ThespatialformulationwasoriginallydescribedinVerHoef, Peterson, and Theobald (2006), with more details given by Ver Hoef and Peterson (2010) and Peterson and Ver Hoef (2010). The spatial data must be formatted in a geographic information system(GIS)priortoimportingitintoR.AcustomArcGIStoolboxhasbeenprovidedtoformat thedata: SpatialToolsfortheAnalysisofRiverSystems(STARS)toolset(PetersonandVerHoef, 2014),andtheSSNpackageisfullydescribedinVerHoef,Peterson,Clifford,andShah(2014). Author(s) JayVerHoefandErinPeterson<[email protected]> References VerHoef,J.M.,Peterson,E.E.andTheobald,D.(2006)SpatialStatisticalModelsthatUseFlow andStreamDistance. EnvironmentalandEcologicalStatistics13,449–464. Ver Hoef, J. M. and Peterson, E. E. (2010) A Moving Average Approach for Spatial Statistical Models of Stream Networks (with Discussion). Journal of the American Statistical Association 105,6–18. DOI:10.1198/jasa.2009.ap08248. Rejoinderpgs. 22–24. Peterson,E.E.andVerHoef,J.M.(2010)AMixed-ModelMoving-AverageApproachtoGeosta- tisticalModelinginStreamNetworks. Ecology91(3),644–651. Peterson,E.E.andVerHoef,J.M.2014.STARS:AnArcGISToolsetUsedtoCalculatetheSpatial InformationNeededtoFitSpatialStatisticalModelstoStreamNetworkData. JournalofStatistical Software56(2): 1–17. 4 additive.function VerHoef,J.M.,Peterson,E.E.,Clifford,D.andShah,R.(2014)SSN:AnRPackageforSpatial StatisticalModelingonStreamNetworks. JournalofStatisticalSoftware56(3): 1–45. additive.function GenerateanAdditiveFunctionValue Description Generate an additive function value based on a proportional influence variable into an additive functionvalue Usage additive.function(ssn, VarName, afvName) Arguments ssn aSpatialStreamNetwork-classobject VarName Thenameofthethevariablethatwillbeusedtocalculatetheadditivefunction value. Thedata.framessn@datamustcontainacolumnwiththisname. afvName Thenameassignedtothecolumnofadditivefunctionvalues,whichareadded to the ssn@data data.frame object, as well as the data.frames for the observed andpredictionsites. Details Calculatingtheadditivefunctionvalues(AFVs)isatwostepprocess;firsttheVarNamevaluesare usedtocalculatethesegmentproportionalinfluences(PIs).ThenthesegmentPI’sareusedtocalcu- latetheAFVsforeachlinesegment,observedsite,andpredictionsiteintheSpatialStreamNetwork- class object. A detailed description of the segment PIs and the steps used to calculate AFVs are provided in Peterson and Ver Hoef (2010; Appendix A). The AFVs can also be calculated using theSpatialToolsfortheAnalysisofRiverSystems(STARS),whichisacustomArcGIS(version 9.3.1)toolbox. Value TheSpatialStreamNetworkobject,ssn,withanewcolumnnamedVarNameincludedinthedata.frames forthelines,observedsites,andpredictionsitestoholdtheAFVs. Author(s) RohanShah<[email protected]> References Peterson,E.E.andVerHoef,J.M.(2010)Amixed-modelmoving-averageapproachtogeostatis- ticalmodelinginstreamnetworks. Ecology91(3),644–651. Peterson E.E.(2011)STARS: Spatial Tools for the Analysis of River Systems: A tutorial. CSIRO TechnicalReportEP111313. 42p. AIC 5 Examples library(SSN) #for examples, copy MiddleFork04.ssn directory to R's temporary directory copyLSN2temp() # NOT RUN # Create a SpatialStreamNetork object that also contains prediction sites #mf04p <- importSSN(paste0(tempdir(),'/MiddleFork04.ssn'), # predpts = "pred1km", o.write = TRUE) #use mf04p SpatialStreamNetwork object, already created data(mf04p) #for examples only, make sure mf04p has the correct path #if you use importSSN(), path will be correct mf04p <- updatePath(mf04p, paste0(tempdir(),'/MiddleFork04.ssn')) #Calculate an additive function value based on an existing column. names(mf04p@data) mf04p <- additive.function(mf04p, "h2oAreaKm2", "areaAFV") #notice that a column called afvArea was already included, and "areaAFV" replicates it # in the lines data head(mf04p@data) # and in the observed points data head(getSSNdata.frame(mf04p)) # and in the prediction points data head(getSSNdata.frame(mf04p, "pred1km")) AIC AICforglmssnobjects Description AIC.glmssnisamethodthatcalculatesAICforfittedglmssnobjects. Usage ## S3 method for class 'glmssn' AIC(object, ..., k = 2) Arguments object anobjectofclassglmssn ... optionallymorefittedmodelobjects k numeric,thepenaltyperparametertobeused;thedefaultk=2istheclassical AIC. Details AICisagenericfunctionandthisimplementsamethodforglmssnobjects 6 as.SpatialLines Value anumericAICvalueforthespecifiedglmssnobject Author(s) JayVerHoef<[email protected]> SeeAlso glmssn Examples library(SSN) #for examples, copy MiddleFork04.ssn directory to R's temporary directory copyLSN2temp() # NOT RUN # Create a SpatialStreamNetork object that also contains prediction sites #mf04p <- importSSN(paste0(tempdir(),'/MiddleFork04.ssn'), # predpts = "pred1km", o.write = TRUE) #use mf04p SpatialStreamNetwork object, already created data(mf04p) #for examples only, make sure mf04p has the correct path #if you use importSSN(), path will be correct mf04p <- updatePath(mf04p, paste0(tempdir(),'/MiddleFork04.ssn')) # get some model fits stored as data objects data(modelFits) #NOT RUN use this one #fitSp <- glmssn(Summer_mn ~ ELEV_DEM + netID, # ssn.object = mf04p, EstMeth = "REML", family = "Gaussian", # CorModels = c("Exponential.tailup","Exponential.taildown", # "Exponential.Euclid"), addfunccol = "afvArea") #for examples only, make sure fitSp has the correct path #if you use importSSN(), path will be correct fitSp$ssn.object <- updatePath(fitSp$ssn.object, paste0(tempdir(),'/MiddleFork04.ssn')) #note the model was fitted using REML, so fixed effects have # been integrated out summary(fitSp) AIC(fitSp) as.SpatialLines MethodstoconvertSpatialStreamNetworkobjectsclassestospclasses as.SpatialLines 7 Description ConvertsSpatialStreamNetworkobjectstospobjects. Usage ## S3 method for class 'SpatialStreamNetwork' as.SpatialLines(x, ...) ## S3 method for class 'SpatialStreamNetwork' as.SpatialPoints(x, data = "Obs", ...) ## S3 method for class 'SpatialStreamNetwork' as.SpatialLinesDataFrame(x, ...) ## S3 method for class 'SpatialStreamNetwork' as.SpatialPointsDataFrame(x, data = "Obs", ...) Arguments x an SpatialStreamNetwork object to be converted to class SpatialLines, Spa- tialPoints,SpatialLinesDataFrameorSpatialPointsDataFramefromthesppack- age. data thedatasetintheSpatialStreamNetworkobjecttoconvert.TheSpatialStreamNetwork objectcanholdmultiplespatialpointdatasets,includingtheobserveddataand multiplepredictiondatasets. SeeSpatialStreamNetwork-class. ... optionalargumentsforspecificmethodswrittenforthesegenerics Value as.SpatialLines.SpatialStreamNetwork converts an object of class SpatialStreamNetwork toanobjectofclassSpatialLinesfromthesppackage,as.SpatialPoints.SpatialStreamNetwork converts an object of class SpatialStreamNetwork to an object of class SpatialPoints from thesppackage,andas.SpatialPointsDataFrame.SpatialStreamNetworkconvertsanobjectof classSpatialStreamNetworktoanobjectofclassSpatialPointsDataFramefromthesppack- age, Author(s) JayVerHoef<[email protected]> SeeAlso spplot Examples library(SSN) #for examples, copy MiddleFork04.ssn directory to R's temporary directory copyLSN2temp() # NOT RUN # Create a SpatialStreamNetork object that also contains prediction sites 8 binSp #mf04p <- importSSN(paste0(tempdir(),'/MiddleFork04.ssn'), # predpts = "pred1km", o.write = TRUE) #use mf04p SpatialStreamNetwork object, already created data(mf04p) #for examples only, make sure mf04p has the correct path #if you use importSSN(), path will be correct mf04p <- updatePath(mf04p, paste0(tempdir(),'/MiddleFork04.ssn')) names(mf04p) #--------- # make plots using sp methods #--------- #plot the stream lines plot(as.SpatialLines(mf04p), col = "blue") # add the observed locations with size proportional # to mean summer temperature plot(as.SpatialPoints(mf04p), pch = 19, cex = as.SpatialPointsDataFrame(mf04p)$Summer_mn/9 , add = TRUE) # add the prediction locations on the 1 km spacing plot(as.SpatialPoints(mf04p, data = "pred1km"), cex = 1.5, add = TRUE) # add the dense set of points for block prediction on Knapp segment plot(as.SpatialPoints(mf04p, data = "Knapp"), pch = 19, cex = 0.3, col = "red", add = TRUE) binSp FittedglmssnobjectforexampledatasetMiddleFork.ssn Description TheMiddleFork04.ssndatafoldercontainsthespatial,attribute,andtopologicalinformationneeded toconstructaspatialstreamnetworkobjectusingtheSSNpackage. Thisisafittedmodelusingthe glmssnfunction. Details Seethehelpforglmssnforhowthemodelwascreated. Examples library(SSN) data(modelFits) ls() BlockPredict 9 BlockPredict BlockPredictonforStreamsData Description Blockpredictionforobjectsofclassglmssn-class Usage BlockPredict(object, predpointsID) Arguments object anobjectofclassglmssn predpointsID avalidpredictionpointsID Details Thisfunctionoperatesonglmssnobjectsinmuchthesamewayasthepredictfunction.BlockPredict usesthelocationsinthepredpointsIDdatasettocomputetheaveragepredictionvalueinthearea definedbythepredictionlocations. Thesepredictionlocationsareusedtoapproximatetheintegral overthatarea,sotheyshouldbeevenlyspacedanddenseintheareawhereblockpredictionisde- sired. TheuserneedstocreatethesepredictionlocationsandincludethemintheSSNobjectprior tofittingthemodelwithglmssn. Value Adata.framewithonerowandtwocolumns. Thefirstcolumn, BlockPredEst, istheaveragepre- dictionvalue,andthesecondcolumn,BlockPredSE,isthestandarderroroftheblockprediction. Author(s) JayVerHoef<[email protected]> References Ver Hoef, J. M.. Peterson, E. E. and Theobald, D. (2006) Spatial statistical models that use flow andstreamdistance. EnvironmentalandEcologicalStatistics13,449-464. DOI:10.1007/s10651- 006-0022-8. Examples ## Not run: library(SSN) #for examples, copy MiddleFork04.ssn directory to R's temporary directory copyLSN2temp() # NOT RUN 10 BLUP # Create a SpatialStreamNetork object that also contains prediction sites #mf04p <- importSSN(paste0(tempdir(),'/MiddleFork04.ssn'), # predpts = "pred1km", o.write = TRUE) #use mf04p SpatialStreamNetwork object, already created data(mf04p) #for examples only, make sure mf04p has the correct path #if you use importSSN(), path will be correct mf04p <- updatePath(mf04p, paste0(tempdir(),'/MiddleFork04.ssn')) # Not needed: already added, # add densely gridded prediction points for two stream segments # mf04p <- importPredpts(mf04p, "Knapp", "ssn") # mf04p <- importPredpts(mf04p, "CapeHorn", "ssn") names(mf04p) # see densely gridded prediction points on stream plot(mf04p, PredPointsID = "Knapp") # you could fit the model #fitSpBk <- glmssn(Summer_mn ~ ELEV_DEM + netID, # ssn.object = mf04p, EstMeth = "REML", family = "Gaussian", # CorModels = c("Exponential.tailup","Exponential.taildown", # "Exponential.Euclid"), addfunccol = "afvArea") # or load the pre-fit model data(modelFits) fitSpBk$ssn.object <- updatePath(fitSpBk$ssn.object, paste0(tempdir(),'/MiddleFork04.ssn')) # one-at-a-time predictions for CapeHorn stream ## NOTE: need the amongpreds distance matrices for block prediction createDistMat(mf04p, predpts = "CapeHorn", o.write = TRUE, amongpreds = TRUE) fitSpPredC <- predict(fitSpBk, "CapeHorn") # plot densely gridded prediction points on stream plot(fitSpPredC, "Summer_mn") # block prediction for CapeHorn stream BlockPredict(fitSpBk, "CapeHorn") ## Another example # one-at-a-time predictions for Knapp stream createDistMat(mf04p, predpts = "Knapp", o.write = TRUE, amongpreds = TRUE) fitSpPredK <- predict(fitSpBk, "Knapp") # plot densely gridded prediction points on stream plot(fitSpPredK, "Summer_mn") # block prediction for Knapp stream BlockPredict(fitSpBk, "Knapp") ## End(Not run)

See more

The list of books you might like