**for**

__archive__**R-sig-geo**, not a forum. It is not possible to post through Nabble - you may not start a new thread nor follow up an existing thread. If you wish to post, but are not subscribed to the list through the list homepage, subscribe first

**(through the list homepage, not via Nabble)**and post from your subscribed email address. Until 2015-06-20, subscribers could post through Nabble, but policy has been changed as too many non-subscribers misunderstood the interface.

*Updated:*28 min 50 sec ago

### inconsistent results from moran.test()

Having my own spatial weight matrix, I converted it to a listw format and

calculated the Moran index. The codes are listed below:

Wod_lw<-mat2listw(Wod)

moran.test(mydata$Ties_processed,Wod_lw, randomisation=TRUE)

However, after I generated a gal file, imported it, converted it back to a

listw file, and re-calculated the Moran index with the following codes, the

results became totally different (0.1624 vs. 0.1942):

write.nb.gal(Wod_lw$neighbours,"Wod.gal")

Wod.gal.nb <- read.gal(file="Wod.gal")

Wod_lw2<-nb2listw(Wod.gal.nb)

moran.test(mydata$Ties_processed,Wod_lw, randomisation=TRUE)

moran.test(mydata$Ties_processed,Wod_lw2, randomisation=TRUE)

I don't know where the problem is. I would appreciate if anyone can help me

with this. Thank you

[[alternative HTML version deleted]]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Re: inference of local Gi* using permutations

of res. It is an n by nsim+1 matrix where the n columns are the permutation

results using sample() and the last column is the actual z values of G_i*s.

The following line of code was modified to do the permutations: (i in

1:nsim) res[i] <- moran(sample(x), listw, n, S0, zero.policy)$I. This could

be wrong since the sample() does not fix the value of interest at i. Are

there any functions in R can do this in a correct way? How do we calculate

the p-values after we get the n by nsim matrix? Thank you!

On Thu, Mar 7, 2019 at 8:05 AM Roger Bivand <[hidden email]> wrote:

> On Wed, 6 Mar 2019, Jay Wang wrote:

>

> > Hello,

> >

> > I am currently using the localG () in spdep package, I was wondering if

> we

> > can have a conditional permutation-based inference to get the P value for

> > every Gi*. I saw that a Mote Carlo simulation is used in Moran.MC(), and

> I

> > borrowed the following codes from this function and tried to see if I can

> > do a permutation for localG():

> >

> > pvals<-matrix(0, nrow = V, ncol = 1)

> > for (i in 1:V){

> > rankresi<-rank(res[i, ])

> > xranki <- rankresi[length(res[i, ])]

> > diffi <- nsim - xranki

> > diffi <- ifelse(diffi > 0, diffi, 0)

> > pvali <- punif((diffi + 1)/(nsim + 1))

> > pvals[i,]<-pvali

> > }

>

> Monte Carlo or Hope type tests or permutation bootstraps work like

> analytical permutation in the global case, and are redundant for that

> reason. Monte Carlo (conditional permutation) in the local case requires

> that there is no global autocorrelation or other mis-specifications.

>

> Your code snippet is not an example, and I think is not how permutation is

> actually done. In the local case in ArcGIS, GeoDa, etc., you fix the value

> of interest at i, randomly re-assign all the values to the other

> observations, and recompute the local indicator at i, doing this say 499

> times. Then you move on to the next i, and repeat. In your snippet, we

> cannot see where res is coming from. Is this an n by nsim matrix from nsim

> runs? Might you be needing to compare the sample values with the observed

> value? If you are outputting Z-values of G_i anyway, you may need to step

> back to the actual G_i (here from spdep):

>

> attr(localG(..., return_internals=TRUE), "internals")[,1]

>

> Then

>

> mns <- apply(res, 1, mean)

> sds <- apply(res, 1, sd)

> permZ <- (obs_localG - mns)/sds

>

> are z values that can be considered as drawn from the normal. However, I

> advise against inference unless the assumptions are met, and p-values must

> be adjusted anyway.

>

> Roger

>

> >

> > After running these codes with several different datasets, I found that

> all

> > the negative Gi*s have very high P values say 0.999 with 999

> permutations,

> > meaning that there are no significant cold spots. Where is the problem?

> How

> > can we do conditional permutation-based inference for localG() with R

> > spdep? I understand the critics of permutation-based inference for local

> > indicators, but I just want to explore this. Thank you!

> >

> > Best

> >

> > [[alternative HTML version deleted]]

> >

> > _______________________________________________

> > R-sig-Geo mailing list

> > [hidden email]

> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo

> >

>

> --

> Roger Bivand

> Department of Economics, Norwegian School of Economics,

> Helleveien 30, N-5045 Bergen, Norway.

> voice: +47 55 95 93 55; e-mail: [hidden email]

> https://orcid.org/0000-0003-2392-6140

> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

>

[[alternative HTML version deleted]]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Re: inference of local Gi* using permutations

> Hello,

>

> I am currently using the localG () in spdep package, I was wondering if we

> can have a conditional permutation-based inference to get the P value for

> every Gi*. I saw that a Mote Carlo simulation is used in Moran.MC(), and I

> borrowed the following codes from this function and tried to see if I can

> do a permutation for localG():

>

> pvals<-matrix(0, nrow = V, ncol = 1)

> for (i in 1:V){

> rankresi<-rank(res[i, ])

> xranki <- rankresi[length(res[i, ])]

> diffi <- nsim - xranki

> diffi <- ifelse(diffi > 0, diffi, 0)

> pvali <- punif((diffi + 1)/(nsim + 1))

> pvals[i,]<-pvali

> }

Monte Carlo or Hope type tests or permutation bootstraps work like

analytical permutation in the global case, and are redundant for that

reason. Monte Carlo (conditional permutation) in the local case requires

that there is no global autocorrelation or other mis-specifications.

Your code snippet is not an example, and I think is not how permutation is

actually done. In the local case in ArcGIS, GeoDa, etc., you fix the value

of interest at i, randomly re-assign all the values to the other

observations, and recompute the local indicator at i, doing this say 499

times. Then you move on to the next i, and repeat. In your snippet, we

cannot see where res is coming from. Is this an n by nsim matrix from nsim

runs? Might you be needing to compare the sample values with the observed

value? If you are outputting Z-values of G_i anyway, you may need to step

back to the actual G_i (here from spdep):

attr(localG(..., return_internals=TRUE), "internals")[,1]

Then

mns <- apply(res, 1, mean)

sds <- apply(res, 1, sd)

permZ <- (obs_localG - mns)/sds

are z values that can be considered as drawn from the normal. However, I

advise against inference unless the assumptions are met, and p-values must

be adjusted anyway.

Roger

>

> After running these codes with several different datasets, I found that all

> the negative Gi*s have very high P values say 0.999 with 999 permutations,

> meaning that there are no significant cold spots. Where is the problem? How

> can we do conditional permutation-based inference for localG() with R

> spdep? I understand the critics of permutation-based inference for local

> indicators, but I just want to explore this. Thank you!

>

> Best

>

> [[alternative HTML version deleted]]

>

> _______________________________________________

> R-sig-Geo mailing list

> [hidden email]

> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

>

--

Roger Bivand

Department of Economics, Norwegian School of Economics,

Helleveien 30, N-5045 Bergen, Norway.

voice: +47 55 95 93 55; e-mail: [hidden email]

https://orcid.org/0000-0003-2392-6140

https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Roger Bivand

Department of Economics

Norwegian School of Economics

Helleveien 30

N-5045 Bergen, Norway

### Re: Line graph with over 70 lines plotted against time-Resolved

My issue has been resolved, thanks to Byman, a R-sig-Geo member for

the help. Just to refresh my question,/**//*I needed to plot a line

graph of one variable collected over 72 sites(areas) by time (date)

which meant 72 lines on the same graph*/.

Here is the solution/code below in case others might have similar issue.

/ # Plot several line graphs//

// library(ggplot2)//

// library(reshape2)//

//

// #changes this line below accordingly//

// dat <- read.table(file.path(""), header = TRUE, sep = ",")//

//

// #Melt the data for easy plotting//

// data <- melt(dat, id = c("DISTRICTS_", "area_name", "Year","Quarter",

"Date"))//

//

// # format the date column//

// data$Date <- as.Date(data$Date, format = "%d/%m/%Y")//

// #Subset and select the target variable//

// g <- ggplot()//

// g <- g + geom_line(data = data %% filter(variable ==

"Mean.Max.Temp"), aes(x = Date, y = value, group = area_name)) #, colour

= area_name))//

// ####end of script##############/

[[alternative HTML version deleted]]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### inference of local Gi* using permutations

I am currently using the localG () in spdep package, I was wondering if we

can have a conditional permutation-based inference to get the P value for

every Gi*. I saw that a Mote Carlo simulation is used in Moran.MC(), and I

borrowed the following codes from this function and tried to see if I can

do a permutation for localG():

pvals<-matrix(0, nrow = V, ncol = 1)

for (i in 1:V){

rankresi<-rank(res[i, ])

xranki <- rankresi[length(res[i, ])]

diffi <- nsim - xranki

diffi <- ifelse(diffi > 0, diffi, 0)

pvali <- punif((diffi + 1)/(nsim + 1))

pvals[i,]<-pvali

}

After running these codes with several different datasets, I found that all

the negative Gi*s have very high P values say 0.999 with 999 permutations,

meaning that there are no significant cold spots. Where is the problem? How

can we do conditional permutation-based inference for localG() with R

spdep? I understand the critics of permutation-based inference for local

indicators, but I just want to explore this. Thank you!

Best

[[alternative HTML version deleted]]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Announcing the "Summer School on Geospatial Data Science with R in Jena"

Please share this fantastic opportunity with all interested parties and refer to the official website for more information on how to apply, the program and the invited lecturers:

https://jupiter.geogr.uni-jena.de/summerschool/about/

We are looking forward to welcoming you in Jena!

Jannes

*Applicants from Germany are welcome to apply but only a limited number can be admitted and no funding can be granted.

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Line graph with over 70 lines plotted against time

I'm currently working on a dataset with 72 areas, recorded in quarterly

dates (2000-2016). I want to visualise some variables using line graphs

in R but have not found suitable tools in weeks now, as many examples

are for creating a couple lines only. When I use ggplot with date

(factor), it jumbles the dates making the lines uninterpretable. when I

convert the date to "date", it breaks at Year points and doesn't give

continuous lines.

Kindly help.

Thanks

Jailos

On 25/02/2019 08:50, Roger Bivand wrote:

> On Sun, 24 Feb 2019, [hidden email] wrote:

>

>> Hello Roger,

>>

>> thank you for your answer.

>>

>> I tried:

>> > gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

>> + bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

>> + fit.points=Daten10, predictions=TRUE, fittedGWRobject=gwrG)

>>

>> Now the prediction works, but when I give out the result, I get this

>> error:

>>

>> Error in sqrt(x$results$sigma2.b) :

>> non-numeric argument to mathematical function

>> How can I solve this problem?

>

> I am not looking over your shoulder. Always provide the code verbatim,

> if I guess which mess you are in, I may get the wrong mess.

>

> Generally, I advise against GWR in all settings, it should only ever

> be used for exploring data for non-stationarity.

>

> Roger

>

>>

>> Thank you,

>> Christoph

>>

>>

>> > Thank you for your answer.

>> > I tried to do the transformations before the calculation, but the

>> > Problem is still the same. I think the problem lies in the factor. But

>> > in my model I need the factor, because there is no linear influence of

>> > the year.

>> >

>> > Is there any solution for this Problem?

>> > https://www.dropbox.com/s/fbhwsy3sd333ung/Example.zip?dl=0 The

>> zip-file

>> > in the link contains a picture of str(Daten90) and str(Daten10) and

>> also

>> > my data and R-skript. Var4 is log(Var2).

>> >

>>

>> I see:

>>

>> > gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

>> + bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

>> + fit.points=Daten10, predictions=TRUE)

>> Warning message:

>> In gwr(formula = Ziel ~ Var1 + Var3 + Var4, data = Daten90, bandwidth =

>> bwG, :

>> standard errors set to NA, normalised RSS not available

>>

>> but using your gwrG object and:

>>

>> > gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

>> + bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

>> + fit.points=Daten10, predictions=TRUE, fittedGWRobject=gwrG)

>>

>> I think the model matrix handling of the factor is OK. The problem in

>> the

>> GWmodel::gwr.predict() approach is that the full model matrix

>> approach is

>> used on the formula and data arguments, but not on predictdata, which is

>> coerced to data frame but never regularised by going through

>> model.matrix,

>> hence the error message:

>>

>> Browse[2]>

>> debug: if (any((inde_vars %in% names(predictdata)) == F)) stop("All the

>> independent variables should be included in the predictdata")

>> Browse[2]> inde_vars

>> [1] "Var12006" "Var12007" "Var12008" "Var12009" "Var3" "Var4"

>> Browse[2]> names(predictdata)

>> [1] "OBJECTID" "Rechtswert" "Hochwert" "Var1" "Var2"

>> [6] "Var3" "Ziel" "Var4" "coords.x1" "coords.x2"

>>

>> Had the proper approach been used, the names would have been the same.

>>

>> The relevant part of spgwr::gwr() in R/gwr.R is:

>>

>> if (predictions) {

>> t1 <- try(slot(fit.points, "data"), silent=TRUE)

>> if (class(t1) == "try-error")

>> stop("No data slot in fit.points")

>> predx <- try(model.matrix(delete.response(mt), fit.points))

>> if (class(predx) == "try-error")

>> stop("missing RHS variable in fit.points")

>> if (ncol(predx) != ncol(x))

>> stop("new data matrix columns mismatch")

>> }

>>

>> (lines 71-80)

>>

>> which uses model.matrix() and uses try() to catch mis-matches.

>>

>> Hope this helps,

>>

>> Roger

>>

>> > Christoph

>> >

>> >

>> >

>> >

>> > The first step should be to look at

>> >

>> > str(Daten90)

>> > str(Daten10)

>> >

>> > and if that doesn't solve the problem, then consider a reproducible

>> > example, or at the very least posting the results of the above to this

>> > list.

>> >

>> > Sarah

>> >

>> > On Fri, Feb 22, 2019 at 7:38 AM <[hidden email]> wrote:

>> > >

>> > > Dear all,

>> > >

>> > > I am currently working out a geographically weighted regression, in

>> which

>> > 90% of the data set the model should be calculated and for 10% of the

>> values

>> > to be predicted. For the prediction I use the function gwr.predict

>> from

>> the

>> > package GWModel:

>> > >

>> > > Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base =

>> exp(1))

>> > + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel =

>> > "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

>> > >

>> > > I always get this error, although Daten10 and Daten90 have the same

>> > structure:

>> > > Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2,

>> base =

>> > exp(1)) + Var3, :

>> > > All the independent variables should be included in the predictdata.

>> > >

>> > > Can you tell me what the problem with this code is?

>> > > Or is there any other way for a GWR and the prediction?

>> > >

>> > > Thank you,

>> > > Christoph

>> > > _______________________________________________

>> > > R-sig-Geo mailing list

>> > > [hidden email]

>> > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo

>> >

>> >

>> >

>> > --

>> > Sarah Goslee (she/her)

>> > http://www.numberwright.com

>> >

>> >

>>

>> --

>> Roger Bivand

>> Department of Economics, Norwegian School of Economics,

>> Helleveien 30, N-5045 Bergen, Norway.

>> voice: +47 55 95 93 55; e-mail: [hidden email]

>> https://orcid.org/0000-0003-2392-6140

>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

>>

>>

>

>

> _______________________________________________

> R-sig-Geo mailing list

> [hidden email]

> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

[[alternative HTML version deleted]]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### iPhone app for KML files that has time slider

I am producing some KML files with time spans in them. They work fine with

a time slider on Google Earth Pro on a laptop.

However, the iPhone and iPad Google Earth apps do not support the time

sliders.

Does anyone know if there is an app which does support the time sliders,

please?

Thanks,

Erin

Erin Hodgess, PhD

mailto: [hidden email]

[[alternative HTML version deleted]]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Error when using over

If someone has anyidea what has happened here, please let me know.Thanks

--

SUDHEESH.P.GPostdoctoral Fellow,LTU, Sweden[hidden email]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Re: Geographically weighted regression

> Hello Roger,

>

> thank you for your answer.

>

> I tried:

> > gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

> + bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

> + fit.points=Daten10, predictions=TRUE, fittedGWRobject=gwrG)

>

> Now the prediction works, but when I give out the result, I get this error:

>

> Error in sqrt(x$results$sigma2.b) :

> non-numeric argument to mathematical function

> How can I solve this problem? I am not looking over your shoulder. Always provide the code verbatim, if

I guess which mess you are in, I may get the wrong mess.

Generally, I advise against GWR in all settings, it should only ever be

used for exploring data for non-stationarity.

Roger

>

> Thank you,

> Christoph

>

>

> > Thank you for your answer.

> > I tried to do the transformations before the calculation, but the

> > Problem is still the same. I think the problem lies in the factor. But

> > in my model I need the factor, because there is no linear influence of

> > the year.

> >

> > Is there any solution for this Problem?

> > https://www.dropbox.com/s/fbhwsy3sd333ung/Example.zip?dl=0 The zip-file

> > in the link contains a picture of str(Daten90) and str(Daten10) and also

> > my data and R-skript. Var4 is log(Var2).

> >

>

> I see:

>

> > gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

> + bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

> + fit.points=Daten10, predictions=TRUE)

> Warning message:

> In gwr(formula = Ziel ~ Var1 + Var3 + Var4, data = Daten90, bandwidth =

> bwG, :

> standard errors set to NA, normalised RSS not available

>

> but using your gwrG object and:

>

> > gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

> + bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

> + fit.points=Daten10, predictions=TRUE, fittedGWRobject=gwrG)

>

> I think the model matrix handling of the factor is OK. The problem in the

> GWmodel::gwr.predict() approach is that the full model matrix approach is

> used on the formula and data arguments, but not on predictdata, which is

> coerced to data frame but never regularised by going through model.matrix,

> hence the error message:

>

> Browse[2]>

> debug: if (any((inde_vars %in% names(predictdata)) == F)) stop("All the

> independent variables should be included in the predictdata")

> Browse[2]> inde_vars

> [1] "Var12006" "Var12007" "Var12008" "Var12009" "Var3" "Var4"

> Browse[2]> names(predictdata)

> [1] "OBJECTID" "Rechtswert" "Hochwert" "Var1" "Var2"

> [6] "Var3" "Ziel" "Var4" "coords.x1" "coords.x2"

>

> Had the proper approach been used, the names would have been the same.

>

> The relevant part of spgwr::gwr() in R/gwr.R is:

>

> if (predictions) {

> t1 <- try(slot(fit.points, "data"), silent=TRUE)

> if (class(t1) == "try-error")

> stop("No data slot in fit.points")

> predx <- try(model.matrix(delete.response(mt), fit.points))

> if (class(predx) == "try-error")

> stop("missing RHS variable in fit.points")

> if (ncol(predx) != ncol(x))

> stop("new data matrix columns mismatch")

> }

>

> (lines 71-80)

>

> which uses model.matrix() and uses try() to catch mis-matches.

>

> Hope this helps,

>

> Roger

>

> > Christoph

> >

> >

> >

> >

> > The first step should be to look at

> >

> > str(Daten90)

> > str(Daten10)

> >

> > and if that doesn't solve the problem, then consider a reproducible

> > example, or at the very least posting the results of the above to this

> > list.

> >

> > Sarah

> >

> > On Fri, Feb 22, 2019 at 7:38 AM <[hidden email]> wrote:

> > >

> > > Dear all,

> > >

> > > I am currently working out a geographically weighted regression, in

> which

> > 90% of the data set the model should be calculated and for 10% of the

> values

> > to be predicted. For the prediction I use the function gwr.predict from

> the

> > package GWModel:

> > >

> > > Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base =

> exp(1))

> > + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel =

> > "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

> > >

> > > I always get this error, although Daten10 and Daten90 have the same

> > structure:

> > > Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2, base =

> > exp(1)) + Var3, :

> > > All the independent variables should be included in the predictdata.

> > >

> > > Can you tell me what the problem with this code is?

> > > Or is there any other way for a GWR and the prediction?

> > >

> > > Thank you,

> > > Christoph

> > > _______________________________________________

> > > R-sig-Geo mailing list

> > > [hidden email]

> > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo

> >

> >

> >

> > --

> > Sarah Goslee (she/her)

> > http://www.numberwright.com

> >

> >

>

> --

> Roger Bivand

> Department of Economics, Norwegian School of Economics,

> Helleveien 30, N-5045 Bergen, Norway.

> voice: +47 55 95 93 55; e-mail: [hidden email]

> https://orcid.org/0000-0003-2392-6140

> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

>

> --

Roger Bivand

Department of Economics, Norwegian School of Economics,

Helleveien 30, N-5045 Bergen, Norway.

voice: +47 55 95 93 55; e-mail: [hidden email]

https://orcid.org/0000-0003-2392-6140

https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Roger Bivand

Department of Economics

Norwegian School of Economics

Helleveien 30

N-5045 Bergen, Norway

### A new version (1.2.0) of the “spm” package for spatial predictive modelling is now on CRAN. [SEC=UNCLASSIFIED]

Dear R users,

A new version (1.2.0) of the “spm” package for spatial predictive modelling is now available on CRAN.

The introductory vignette is available here:

https://cran.rstudio.com/web/packages/spm/vignettes/spm.html

In this version, two additional functions, avi and rvi have been added; and some typos in the help files have been corrected.

avi: to calculate averaged variable importance (avi) for ranfom forest; and

rvi: to calculate relative variable influence (rvi) for generalised boosted regression modelling (gbm).

As always, if you find any bugs and have any suggestions, please send me an email! Thanks in advance!

Kind regards,

**Jin Li, PhD
****|****
**Spatial Modeller / Computational Statistician

National Earth and Marine Observations
**|
**Environmental Geoscience Division

t: +61 2 6249 9899 www.ga.gov.au

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

**mg_info.txt**(615 bytes) Download Attachment

### Re: Geographically weighted regression

+ bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

+ fit.points=Daten10, predictions=TRUE, fittedGWRobject=gwrG) Now the prediction works, but when I give out the result, I get this error: Error in sqrt(x$results$sigma2.b) : non-numeric argument to mathematical function How can I solve this problem? Thank you, Christoph

> Thank you for your answer.

> I tried to do the transformations before the calculation, but the

> Problem is still the same. I think the problem lies in the factor. But

> in my model I need the factor, because there is no linear influence of

> the year.

>

> Is there any solution for this Problem?

> https://www.dropbox.com/s/fbhwsy3sd333ung/Example.zip?dl=0 The zip-file

> in the link contains a picture of str(Daten90) and str(Daten10) and also

> my data and R-skript. Var4 is log(Var2).

>

I see:

> gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

+ bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

+ fit.points=Daten10, predictions=TRUE)

Warning message:

In gwr(formula = Ziel ~ Var1 + Var3 + Var4, data = Daten90, bandwidth =

bwG, :

standard errors set to NA, normalised RSS not available

but using your gwrG object and:

> gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

+ bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

+ fit.points=Daten10, predictions=TRUE, fittedGWRobject=gwrG)

I think the model matrix handling of the factor is OK. The problem in the

GWmodel::gwr.predict() approach is that the full model matrix approach is

used on the formula and data arguments, but not on predictdata, which is

coerced to data frame but never regularised by going through model.matrix,

hence the error message:

Browse[2]>

debug: if (any((inde_vars %in% names(predictdata)) == F)) stop("All the

independent variables should be included in the predictdata")

Browse[2]> inde_vars

[1] "Var12006" "Var12007" "Var12008" "Var12009" "Var3" "Var4"

Browse[2]> names(predictdata)

[1] "OBJECTID" "Rechtswert" "Hochwert" "Var1" "Var2"

[6] "Var3" "Ziel" "Var4" "coords.x1" "coords.x2"

Had the proper approach been used, the names would have been the same.

The relevant part of spgwr::gwr() in R/gwr.R is:

if (predictions) {

t1 <- try(slot(fit.points, "data"), silent=TRUE)

if (class(t1) == "try-error")

stop("No data slot in fit.points")

predx <- try(model.matrix(delete.response(mt), fit.points))

if (class(predx) == "try-error")

stop("missing RHS variable in fit.points")

if (ncol(predx) != ncol(x))

stop("new data matrix columns mismatch")

}

(lines 71-80)

which uses model.matrix() and uses try() to catch mis-matches.

Hope this helps,

Roger

> Christoph

>

>

>

>

> The first step should be to look at

>

> str(Daten90)

> str(Daten10)

>

> and if that doesn't solve the problem, then consider a reproducible

> example, or at the very least posting the results of the above to this

> list.

>

> Sarah

>

> On Fri, Feb 22, 2019 at 7:38 AM <[hidden email]> wrote:

> >

> > Dear all,

> >

> > I am currently working out a geographically weighted regression, in which

> 90% of the data set the model should be calculated and for 10% of the values

> to be predicted. For the prediction I use the function gwr.predict from the

> package GWModel:

> >

> > Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base = exp(1))

> + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel =

> "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

> >

> > I always get this error, although Daten10 and Daten90 have the same

> structure:

> > Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2, base =

> exp(1)) + Var3, :

> > All the independent variables should be included in the predictdata.

> >

> > Can you tell me what the problem with this code is?

> > Or is there any other way for a GWR and the prediction?

> >

> > Thank you,

> > Christoph

> > _______________________________________________

> > R-sig-Geo mailing list

> > [hidden email]

> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo

>

>

>

> --

> Sarah Goslee (she/her)

> http://www.numberwright.com

>

>

--

Roger Bivand

Department of Economics, Norwegian School of Economics,

Helleveien 30, N-5045 Bergen, Norway.

voice: +47 55 95 93 55; e-mail: [hidden email]

https://orcid.org/0000-0003-2392-6140

https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Re: Geographically weighted regression

> Thank you for your answer.

> I tried to do the transformations before the calculation, but the

> Problem is still the same. I think the problem lies in the factor. But

> in my model I need the factor, because there is no linear influence of

> the year.

>

> Is there any solution for this Problem?

> https://www.dropbox.com/s/fbhwsy3sd333ung/Example.zip?dl=0 The zip-file

> in the link contains a picture of str(Daten90) and str(Daten10) and also

> my data and R-skript. Var4 is log(Var2).

> I see:

> gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

+ bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

+ fit.points=Daten10, predictions=TRUE)

Warning message:

In gwr(formula = Ziel ~ Var1 + Var3 + Var4, data = Daten90, bandwidth =

bwG, :

standard errors set to NA, normalised RSS not available

but using your gwrG object and:

> gwrGp <- gwr(formula=Ziel~ Var1 + Var3 + Var4, data = Daten90,

+ bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,

+ fit.points=Daten10, predictions=TRUE, fittedGWRobject=gwrG)

I think the model matrix handling of the factor is OK. The problem in the

GWmodel::gwr.predict() approach is that the full model matrix approach is

used on the formula and data arguments, but not on predictdata, which is

coerced to data frame but never regularised by going through model.matrix,

hence the error message:

Browse[2]>

debug: if (any((inde_vars %in% names(predictdata)) == F)) stop("All the

independent variables should be included in the predictdata")

Browse[2]> inde_vars

[1] "Var12006" "Var12007" "Var12008" "Var12009" "Var3" "Var4"

Browse[2]> names(predictdata)

[1] "OBJECTID" "Rechtswert" "Hochwert" "Var1" "Var2"

[6] "Var3" "Ziel" "Var4" "coords.x1" "coords.x2"

Had the proper approach been used, the names would have been the same.

The relevant part of spgwr::gwr() in R/gwr.R is:

if (predictions) {

t1 <- try(slot(fit.points, "data"), silent=TRUE)

if (class(t1) == "try-error")

stop("No data slot in fit.points")

predx <- try(model.matrix(delete.response(mt), fit.points))

if (class(predx) == "try-error")

stop("missing RHS variable in fit.points")

if (ncol(predx) != ncol(x))

stop("new data matrix columns mismatch")

}

(lines 71-80)

which uses model.matrix() and uses try() to catch mis-matches.

Hope this helps,

Roger

> Christoph

>

>

>

>

> The first step should be to look at

>

> str(Daten90)

> str(Daten10)

>

> and if that doesn't solve the problem, then consider a reproducible

> example, or at the very least posting the results of the above to this

> list.

>

> Sarah

>

> On Fri, Feb 22, 2019 at 7:38 AM <[hidden email]> wrote:

> >

> > Dear all,

> >

> > I am currently working out a geographically weighted regression, in which

> 90% of the data set the model should be calculated and for 10% of the values

> to be predicted. For the prediction I use the function gwr.predict from the

> package GWModel:

> >

> > Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base = exp(1))

> + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel =

> "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

> >

> > I always get this error, although Daten10 and Daten90 have the same

> structure:

> > Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2, base =

> exp(1)) + Var3, :

> > All the independent variables should be included in the predictdata.

> >

> > Can you tell me what the problem with this code is?

> > Or is there any other way for a GWR and the prediction?

> >

> > Thank you,

> > Christoph

> > _______________________________________________

> > R-sig-Geo mailing list

> > [hidden email]

> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo

>

>

>

> --

> Sarah Goslee (she/her)

> http://www.numberwright.com

>

> --

Roger Bivand

Department of Economics, Norwegian School of Economics,

Helleveien 30, N-5045 Bergen, Norway.

voice: +47 55 95 93 55; e-mail: [hidden email]

https://orcid.org/0000-0003-2392-6140

https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Roger Bivand

Department of Economics

Norwegian School of Economics

Helleveien 30

N-5045 Bergen, Norway

### Re: Geographically weighted regression

str(Daten90)

str(Daten10)

and if that doesn't solve the problem, then consider a reproducible

example, or at the very least posting the results of the above to this

list.

Sarah

On Fri, Feb 22, 2019 at 7:38 AM <[hidden email]> wrote:

>

> Dear all,

>

> I am currently working out a geographically weighted regression, in which 90% of the data set the model should be calculated and for 10% of the values to be predicted. For the prediction I use the function gwr.predict from the package GWModel:

>

> Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel = "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

>

> I always get this error, although Daten10 and Daten90 have the same structure:

> Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, :

> All the independent variables should be included in the predictdata.

>

> Can you tell me what the problem with this code is?

> Or is there any other way for a GWR and the prediction?

>

> Thank you,

> Christoph

> _______________________________________________

> R-sig-Geo mailing list

> [hidden email]

> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

--

Sarah Goslee (she/her)

http://www.numberwright.com

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Re: Geographically weighted regression

> Hi,

> The formula is wrongly specified, Ziel~ as.factor(Var1) + log(Var2, base

> = exp(1)) + Var3, use the corresponding var-names only.

>

> As I understand, you want to do some calculations with the variables,

> and you can process them in the data frame before using it in this

> command, not in the formula.

Correct, not in the formula in the way that these functions handle the

names made by formula() and model.matrix(). lm() and its prediction

function do seem to handle them correctly, but it is very hard in more

complicated fitting/prediction functions to get this right. Pre-compute

the modified variables so that the package functions just see simple

variables.

Roger

>

> Binbin

>

>

>

>

> Dr Binbin Lu

> Lecturer in School of Remote Sensing and Information Engineering, Wuhan University

> Email: [hidden email]

>

> From: f-c-b

> Date: 2019-02-22 20:37

> To: r-sig-geo

> Subject: [R-sig-Geo] Geographically weighted regression

> Dear all,

>

> I am currently working out a geographically weighted regression, in which 90% of the data set the model should be calculated and for 10% of the values to be predicted. For the prediction I use the function gwr.predict from the package GWModel:

>

> Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel = "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

>

> I always get this error, although Daten10 and Daten90 have the same structure:

> Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, :

> All the independent variables should be included in the predictdata.

>

> Can you tell me what the problem with this code is?

> Or is there any other way for a GWR and the prediction?

>

> Thank you,

> Christoph

>

> [[alternative HTML version deleted]]

>

> _______________________________________________

> R-sig-Geo mailing list

> [hidden email]

> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

>

--

Roger Bivand

Department of Economics, Norwegian School of Economics,

Helleveien 30, N-5045 Bergen, Norway.

voice: +47 55 95 93 55; e-mail: [hidden email]

https://orcid.org/0000-0003-2392-6140

https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Roger Bivand

Department of Economics

Norwegian School of Economics

Helleveien 30

N-5045 Bergen, Norway

### Re: Geographically weighted regression

The formula is wrongly specified, Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, use the corresponding var-names only.

As I understand, you want to do some calculations with the variables, and you can process them in the data frame before using it in this command, not in the formula.

Binbin

Dr Binbin Lu

Lecturer in School of Remote Sensing and Information Engineering, Wuhan University

Email: [hidden email]

From: f-c-b

Date: 2019-02-22 20:37

To: r-sig-geo

Subject: [R-sig-Geo] Geographically weighted regression

Dear all,

I am currently working out a geographically weighted regression, in which 90% of the data set the model should be calculated and for 10% of the values to be predicted. For the prediction I use the function gwr.predict from the package GWModel:

Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel = "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

I always get this error, although Daten10 and Daten90 have the same structure:

Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, :

All the independent variables should be included in the predictdata.

Can you tell me what the problem with this code is?

Or is there any other way for a GWR and the prediction?

Thank you,

Christoph

[[alternative HTML version deleted]]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Re: Geographically weighted regression

str(Daten90)

str(Daten10)

and if that doesn't solve the problem, then consider a reproducible

example, or at the very least posting the results of the above to this

list.

Sarah

On Fri, Feb 22, 2019 at 7:38 AM <[hidden email]> wrote:

>

> Dear all,

>

> I am currently working out a geographically weighted regression, in which 90% of the data set the model should be calculated and for 10% of the values to be predicted. For the prediction I use the function gwr.predict from the package GWModel:

>

> Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel = "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

>

> I always get this error, although Daten10 and Daten90 have the same structure:

> Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, :

> All the independent variables should be included in the predictdata.

>

> Can you tell me what the problem with this code is?

> Or is there any other way for a GWR and the prediction?

>

> Thank you,

> Christoph

> _______________________________________________

> R-sig-Geo mailing list

> [hidden email]

> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

--

Sarah Goslee (she/her)

http://www.numberwright.com

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Re: create a raster time series with negative years (years Before Present)

"Years before 1CE (aka 1AD) will probably not be handled correctly."

On 2/22/19 3:59 PM, Jackson Rodrigues wrote:

> Hey guys,

>

> I need some help to set a time serie (ts) to raster stack, however my

> raster serie has negative ages (years Before Present (yrBP)).

>

> I have tried several codes and packages unsuccessfully.

>

> If succeed, I would like to apply seasonal and other calculations to my

> new raster time serie.

>

> Below are some codes from package rts. I adapted years to negative value

> only as a example.

>

> #####

>> path <- system.file("external", package="rts") # location of files

>> lst <- list.files(path=path,pattern='.asc$',full.names=TRUE)

>> lst # list of raster files

>> r <- stack(lst) # creating a RasterStack object

>> r

>> d <- c("-2000-02-01","-2000-03-01","-2000-04-01","-2000-05-01") #

> corresponding dates to 4 rasters

>> d <- as.Date(d) # or d <- as.POSIXct(d)

> Error in charToDate(x) :

> character string is not in a standard unambiguous format

>> rt <- rts(r,d) # creating a RasterStackTS object

>> rt

>> plot(rt)

> #########

>

> best,

>

> Jackson Rodrigues

> --

>

> [[alternative HTML version deleted]]

>

> _______________________________________________

> R-sig-Geo mailing list

> [hidden email]

> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

> --

Edzer Pebesma

Institute for Geoinformatics

Heisenbergstrasse 2, 48151 Muenster, Germany

Phone: +49 251 8333081

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

**pEpkey.asc**(2K) Download Attachment

### create a raster time series with negative years (years Before Present)

I need some help to set a time serie (ts) to raster stack, however my

raster serie has negative ages (years Before Present (yrBP)).

I have tried several codes and packages unsuccessfully.

If succeed, I would like to apply seasonal and other calculations to my

new raster time serie.

Below are some codes from package rts. I adapted years to negative value

only as a example.

#####

>path <- system.file("external", package="rts") # location of files

>lst <- list.files(path=path,pattern='.asc$',full.names=TRUE)

>lst # list of raster files

>r <- stack(lst) # creating a RasterStack object

>r

>d <- c("-2000-02-01","-2000-03-01","-2000-04-01","-2000-05-01") #

corresponding dates to 4 rasters

>d <- as.Date(d) # or d <- as.POSIXct(d)

Error in charToDate(x) :

character string is not in a standard unambiguous format

>rt <- rts(r,d) # creating a RasterStackTS object

>rt

>plot(rt)

#########

best,

Jackson Rodrigues

--

[[alternative HTML version deleted]]

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo

### Geographically weighted regression

I am currently working out a geographically weighted regression, in which 90% of the data set the model should be calculated and for 10% of the values to be predicted. For the prediction I use the function gwr.predict from the package GWModel:

Erg<-gwr.predict(formula=Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, data = Daten90,predictdata = Daten10,bw = bwG, kernel = "gaussian",adaptive = FALSE, p = 2, theta = 0, longlat = FALSE)

I always get this error, although Daten10 and Daten90 have the same structure:

Error in gwr.predict(formula = Ziel~ as.factor(Var1) + log(Var2, base = exp(1)) + Var3, : All the independent variables should be included in the predictdata. Can you tell me what the problem with this code is?

Or is there any other way for a GWR and the prediction?

Thank you,

Christoph

_______________________________________________

R-sig-Geo mailing list

[hidden email]

https://stat.ethz.ch/mailman/listinfo/r-sig-geo