Learn R Programming

SpatioTemporal (version 1.1.2)

dropObservations: Drop Observations from a STmodel

Description

Drops observations from STmodel, removing marked observations along with the corresponding locations and recomputes a number of relevant elements.

Usage

dropObservations(STmodel, Ind.cv)

Arguments

STmodel
Model object from which to drop observations.
Ind.cv
A logical vector with one element per observation in STmodel$obs. Observations marked with the TRUE will be dropped from the data structure. Use createCV to create the lo

Value

  • Returns the STmodel without the observations marked by Ind.cv. Only observed locations are retained.

See Also

Other cross-validation functions: computeLTA, createCV, estimateCV.STmodel, predictCV.STmodel, predictNaive

Other STmodel functions: createCV, createDataMatrix, createSTmodel, loglikeST, loglikeSTdim, loglikeSTnaive, predictNaive, processLocation, processLUR, processST, updateCovf

Examples

Run this code
##load data
data(mesa.model)

##Mark 30\% of observations
I <- runif(dim(mesa.model$obs)[1])<.3
##drop these observations
mesa.model.new <- dropObservations(mesa.model, I)

##This reduces the remaining number of observations
print(mesa.model)
print(mesa.model.new)

if( (length(mesa.model$obs$obs)<=length(mesa.model.new$obs$obs)) ||
     (length(mesa.model.new$obs$obs)!=sum(!I)) ){
    stop("drop.observations 1: Observations not dropped")
  }
##create cross validation structure
Icv <- createCV(mesa.model, groups=10)

##drop observations from the second CV group
mesa.model.new <- dropObservations(mesa.model, Icv==2)

##This reduces the remaining number of observations (and locations)
print(mesa.model)
print(mesa.model.new)

if( (length(mesa.model$obs$obs)<=length(mesa.model.new$obs$obs)) ||
     (length(mesa.model.new$obs$obs)!=sum(Icv!=2)) ||
     (dim(mesa.model$locations)[1] <= dim(mesa.model.new$locations)[1]) ){
    stop("drop.observations 2: Observations not dropped")
  }

Run the code above in your browser using DataLab