andrewzm / STRbook

Supplementary package for "Spatio-Temporal Statistics with R" by C.K. Wikle, A. Zammit-Mangion, and N. Cressie
76 stars 48 forks source link

"sill" must be positive.?? #2

Open sue-shine opened 4 years ago

sue-shine commented 4 years ago

Excuse me, sorry to bother you. I have met a question when coding.as the code follows. <loc<-read.csv("F:/1Guichi1991-2015/schdata.SU/location.csv") <date<-read.csv("F:/1Guichi1991-2015/schdata.SU/date.csv") <data<-read.csv("F:/1Guichi1991-2015/schdata.SU/data.csv")   <library("dplyr") <library("tidyr") <library("STRbook") <library("sp") <library("spacetime")  

STFDF

<spat_part <- SpatialPoints(coords = loc[,c("lon", "lat")])   <date$time<-as.character(date$time)  <temp_part<-date$time    <temp_part <- as.Date(temp_part) <class(date$time)   <data$VillageID<-as.integer(data$VillageID) <all(unique(data$VillageID) == loc$VillageID) <STOBJ1<- STFDF(sp = spat_part,                time = temp_part,                data = data)   <proj4string(STOBJ1) <- CRS("+proj=longlat +ellps=WGS84") <library(gstat) <vv<-variogram(object=p~1,                 data=STOBJ1,               width=2,                 cutoff=28,               tlags=0.01:6.1,tunit="days")   <plot(vv)

separable model

<sepVgm <- vgmST(stModel = "separable",                     space = vgm(10, "Exp", 400, nugget = 0.1),                 time = vgm(10, "Exp", 1, nugget = 0.1),                 sill = 20)   <sepVgm <- fit.StVariogram(vv, sepVgm)  ##Error in vgmST("separable", space = vgm(1 - par[2], as.character(model$space$model[2]), : "sill" must be positive. I can find the problem with my exercise data, could you please help me? <spat_pred_grid<- expand.grid( < lon = seq(117, 118, length = 20), < lat = seq(30, 31, length = 20)) %>% < SpatialPoints(proj4string = CRS(proj4string(STOBJ1))) <gridded(spat_pred_grid) <- TRUE   <temp_pred_grid <- as.Date("1991-06-01") + seq(1, 6, length = 6)     <DE_pred<- STF(sp = spat_pred_grid,                 time = temp_pred_grid)   <STOBJ1 <- as(STOBJ1[,"1991-06-01::1991-06-25"], "STIDF")   <STOBJ1 <- subset(STOBJ1, !is.na(STOBJ1$p))   <pred_kriged <- krigeST(p ~ #1,                        data = STOBJ1,                        newdata = DE_pred, # prediction grid                        modelList = sepVgm, # semivariogram                        computeVar = TRUE)  ##Error in chol.default(A) : the leading minor of order 88 is not positive definite

andrewzm commented 4 years ago

Hi Sue, this seems to be a problem with fitting vgmST to your specific data. Often this happens because there is a "trend" component you have not removed. I see your formula is p ~ 1, try putting in some covariates and see if things improve. Also, look closely at the "empirical" spatial and temporal variograms so you have an idea what you are fitting the theoretical variogram too. Hope this helps.

Andrew

On Mon, Jul 6, 2020 at 7:00 PM sue-shine notifications@github.com wrote:

Excuse me, sorry to bother you. I have met a question when coding.as the code follows. <loc<-read.csv("F:/1Guichi1991-2015/schdata.SU/location.csv") <date<-read.csv("F:/1Guichi1991-2015/schdata.SU/date.csv") <data<-read.csv("F:/1Guichi1991-2015/schdata.SU/data.csv")

<library("dplyr") <library("tidyr") <library("STRbook") <library("sp") <library("spacetime")

STFDF

<spat_part <- SpatialPoints(coords = loc[,c("lon", "lat")])

<date$time<-as.character(date$time) <temp_part<-date$time <temp_part <- as.Date(temp_part) <class(date$time)

<data$VillageID<-as.integer(data$VillageID) <all(unique(data$VillageID) == loc$VillageID) <STOBJ1<- STFDF(sp = spat_part, time = temp_part, data = data)

<proj4string(STOBJ1) <- CRS("+proj=longlat +ellps=WGS84") <library(gstat) <vv<-variogram(object=p~1, data=STOBJ1, width=2, cutoff=28, tlags=0.01:6.1,tunit="days")

<plot(vv)

separable model

<sepVgm <- vgmST(stModel = "separable", space = vgm(10, "Exp", 400, nugget = 0.1), time = vgm(10, "Exp", 1, nugget = 0.1), sill = 20) <sepVgm <- fit.StVariogram(vv, sepVgm)

Error in vgmST("separable", space = vgm(1 - par[2],

as.character(model$space$model[2]), : "sill" must be positive. I can find the problem with my exercise data, could you please help me? <spat_pred_grid<- expand.grid( < lon = seq(117, 118, length = 20), < lat = seq(30, 31, length = 20)) %>% < SpatialPoints(proj4string = CRS(proj4string(STOBJ1))) <gridded(spat_pred_grid) <- TRUE

<temp_pred_grid <- as.Date("1991-06-01") + seq(1, 6, length = 6)

<DE_pred<- STF(sp = spat_pred_grid, time = temp_pred_grid)

<STOBJ1 <- as(STOBJ1[,"1991-06-01::1991-06-25"], "STIDF")

<STOBJ1 <- subset(STOBJ1, !is.na(STOBJ1$p))

<pred_kriged <- krigeST(p ~ #1 https://github.com/andrewzm/STRbook/issues/1, data = STOBJ1, newdata = DE_pred, # prediction grid modelList = sepVgm, # semivariogram computeVar = TRUE)

Error in chol.default(A) : the leading minor of order 88 is not

positive definite

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/andrewzm/STRbook/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABEU3NKQOZPIPPTXZCE5SDR2GHEHANCNFSM4ORMR4KQ .

sue-shine commented 4 years ago

Hi, I try to put covariates in, but it didn't work, I wonder if it is convenient to check my exercise data for you.really need help.Thank you!