I have several years of data that needs to be converted to STDFDF. Shapiro.test and Adf.test talk about non-stationarity and non-normal distribution.
particolato_May2021 <- read.delim(file = "Data.txt")
dput(particolato_May2021) ##sample data
##set the stations of the region
stations <- read.csv("stations_CS.csv", header=TRUE)
names(stations)
coord <-cbind(stations$Longitude,stations$Latitude)
plot(coord)
save(stations,file='data/stations.Rdata')
coords <- SpatialPoints(particolato_May2021[, c("Longitude", "Latitude")])
summary(coords)
particolato_sp <- SpatialPointsDataFrame(coords, particolato_May2021)
names(particolato_sp)
is(particolato_sp)
particolato_May2021$Data <- as.POSIXct(particolato_sp$Data, format = "%Y-%m-%d")
save(particolato_May2021,file='data/particolato.Rdata')
##The problem starts here
STFDF_day <- stConstruct(particolato,space=c('Longitude','Latitude'),time='Data',
SpatialObj=SpatialPoints(particolato[,c('Longitude','Latitude')]))
is(STFDF_day)
proj4string(STFDF_day) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
save(STFDF_day,file='data/STFDF_day.Rdata')
load('data/STFDF_day.Rdata')
#Variogram
var <- variogramST(PM10~1,data=STFDF_day,tunit="days",
assumeRegular=F,na.omit=T)
This is an incomplete data set for seven years, and I replaced the missing data with averages for the same days in previous years. I want to conduct space-time kriging and extract data for other unknown points (long, lat) before kriging for the same period for each day. I have following problem:
Found more than one class "xts" in cache; using the first, from namespace 'spacetime'
Also defined by ‘quantmod’
Error in `vectbl_as_row_location()`:
! Must subset rows with a valid subscript vector.
x Subscript `time` must be a simple vector, not a matrix.
Run `rlang::last_error()` to see where the error occurred.
Sample date
structure(list(NetC = c("Cosenza Provincia", "Cosenza Provincia",
"Cosenza Provincia", "Reti Private", "Reti Private"), Stat = c("Citta dei Ragazzi",
"Rende", "Acri", "Firmo", "Schiavonea"), ID = c("IT1938A", "IT2086A",
"IT2110A", "IT1766A", "IT2090A"), Longitude = c(16.2452, 16.2433,
16.3868, 16.194, 16.5468), Latitude = c(39.3134, 39.3389, 39.4896,
39.7138, 39.6518), Data = structure(c(1619820000, 1619820000,
1619820000, 1619820000, 1619820000), tzone = "", class = c("POSIXct",
"POSIXt")), PM10 = c(28.48, 29.31, 32.3, 103.06, 19.83), day = c("01",
"01", "01", "01", "01"), month = c("05", "05", "05", "05", "05"
), year = c("2021", "2021", "2021", "2021", "2021"), avePM10 = c(17.53875,
20.6028571428571, 19.4285714285714, 29.46625, 18.7257142857143
), comment = c(NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_)), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame"))
Stations:
structure(list(Location = c("IT1766A", "IT1938A", "IT2086A",
"IT2090A", "IT2110A"), Longitude = c(16.19397, 16.24517, 16.24334,
16.54677, 16.3868), Latitude = c(39.71376, 39.3134, 39.33893,
39.65176, 39.48963), station_type = c("Industrial", "Background",
"Traffic", "Industrial", "Background"), station_area = c("Rural",
"Urban", "Urban", "Rural", "Urban")), class = "data.frame", row.names = c(NA,
-5L))
df
, and then save it to a file, and then read back from a different file name. I've tried writing it and reading back from the same file, but then the next line fails because the dates are "2021-06-26" but you try and convert them withformat = "%m/%d/%Y"
so I get NA for all the dates after that. Which makes me think maybe you are reading them from a different file. I'm not sure even why you take the data on this round trip via a file when you should be able to work withdf
directly.Error in vectbl_as_row_location(): ! Must subset rows with a valid subscript vector. x Subscript time must be a simple vector, not a matrix. --- Backtrace: 1. spacetime::stConstruct(...) 14. rlang::cnd_signal(x)
##The problem starts here
references an object calledparticolato
-stConstruct(particolato,space=
but you don't show what this object is. This is why you have to make sure your code runs when cut and pasted into a clean R session, otherwise we can't help because we don't know what objects you have and how you are getting the error you are seeing. Start from reading your sample data and stations, and work through to the error.