NCAR / fields

GNU General Public License v2.0
27 stars 8 forks source link

custom knots for thin plate spline fails #5

Open brycefrank opened 4 years ago

brycefrank commented 4 years ago

Hello!

Thank you for the hard work on this package, it is incredibly exhaustive and useful.

One thing I am struggling with is fitting a thin plate spline with knots that are not at the sample locations. Here is an example that slightly modifies an example given in the manual:

library(fields)
data(ozone2)
y16<- ozone2$y[16,]
# there are some missing values -- remove them
good<- !is.na( y16)
y<- y16[good]
x<- ozone2$lon.lat[ good,]
#
# the knots can be arbitrary but just for fun find them with a space
# filling design. Here we select 50 from the full set of 147 points
#
xknots<- cover.design( x, 50, num.nn= 75)$design # select 50 knot points
Tps(x,y, knots=xknots)

I receive the error

Error in eigen(A + B, symmetric = TRUE) : 
  infinite or missing values in 'x'

I am able to fit a thin plate spline using knots not at the sample locations using some code I have written, but I would like to take advantage of this package to fit the lambda parameter. I have been using this publication for my own code so far:

Cicchitelli, Giuseppe, and Giorgio E. Montanari. "Model‐assisted estimation of a spatial population mean." International Statistical Review 80, no. 1 (2012): 111-126.

Any insight on why this error is showing up would be helpful.

dnychka commented 4 years ago

Bryce, Was away from email and just saw this. Will figure out what the issue is. Doug

Douglas Nychka Personal email Cell 3037253199

From: Bryce Frank notifications@github.com Reply-To: NCAR/fields reply@reply.github.com Date: Thursday, August 6, 2020 at 9:35 AM To: NCAR/fields fields@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [NCAR/fields] custom knots for thin plate spline fails (#5)

Hello!

Thank you for the hard work on this package, it is incredibly exhaustive and useful.

One thing I am struggling with is fitting a thin plate spline with knots that are not at the sample locations. Here is an example that slightly modifies an example given in the manual:

library(fields)

data(ozone2)

y16<- ozone2$y[16,]

there are some missing values -- remove them

good<- !is.na( y16)

y<- y16[good]

x<- ozone2$lon.lat[ good,]

#

the knots can be arbitrary but just for fun find them with a space

filling design. Here we select 50 from the full set of 147 points

#

xknots<- cover.design( x, 50, num.nn= 75)$design # select 50 knot points

Tps(x,y, knots=xknots)

I receive the error

Error in eigen(A + B, symmetric = TRUE) :

infinite or missing values in 'x'

I am able to fit a thin plate spline using knots not at the sample locations using some code I have written, but I would like to take advantage of this package to fit the lambda parameter. I have been using this publication for my own code so far:

Cicchitelli, Giuseppe, and Giorgio E. Montanari. "Model\assisted estimation of a spatial population mean." International Statistical Review 80, no. 1 (2012): 111-126.https://www.jstor.org/stable/pdf/23257169.pdf?casa_token=lVL5qok3eLYAAAAA:3Io_EwoCn0MgqgVH8ku_Ua-fBxMhF0hLQ428WQ7nwZCsVex2RAe2ms-g30lTcvnxAM8SkkZmTTdHIc_umHOEpwcxWklvvenM6teX_VhUfcDDnbBoOwo

Any insight on why this error is showing up would be helpful.

― You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/NCAR/fields/issues/5, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADHJ7U7S4OBULHSNKIVBF53R7LEVLANCNFSM4PWWZ3IQ.

brycefrank commented 4 years ago

Doug,

It is no problem! I did a bit of digging myself and could not find any obvious issues. It is clear that there are three negative values in the eigenvalues. If I remember correctly it was around here:

https://github.com/NCAR/fields/blob/f89f156571a2f64b48a147f551fad2cf4788b029/fields/R/fields.diagonalize2.R#L24

Although it could have been in fields.diagonalize.R, I can't recall. This leads to the error when the square root is taken here:

https://github.com/NCAR/fields/blob/f89f156571a2f64b48a147f551fad2cf4788b029/fields/R/fields.diagonalize2.R#L31

In any case I have moved on to another method for my own reasons so it is not urgent.

dnychka commented 4 years ago

OK Bryce. There are alternatives in fields and in the package LatticeKrig to handle large problems and so the need to resort to knots is not as useful.

E.g. fastTps should be able to handle several thousand locations.

Douglas Nychka Personal email Cell 3037253199

From: Bryce Frank notifications@github.com Reply-To: NCAR/fields reply@reply.github.com Date: Wednesday, August 12, 2020 at 11:57 AM To: NCAR/fields fields@noreply.github.com Cc: Douglas Nychka douglasnychka@gmail.com, Comment comment@noreply.github.com Subject: Re: [NCAR/fields] custom knots for thin plate spline fails (#5)

Doug,

It is no problem! I did a bit of digging myself and could not find any obvious issues. It is clear that there are three negative values in the eigenvalues. If I remember correctly it was around here:

https://github.com/NCAR/fields/blob/f89f156571a2f64b48a147f551fad2cf4788b029/fields/R/fields.diagonalize2.R#L31

Although it could have been in fields.diagonalize.R, I can't recall. This leads to the error when the square root is taken here:

https://github.com/NCAR/fields/blob/f89f156571a2f64b48a147f551fad2cf4788b029/fields/R/fields.diagonalize2.R#L31

In any case I have moved on to another method for my own reasons so it is not urgent.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/NCAR/fields/issues/5#issuecomment-673023242, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADHJ7U6KGB5HVNW7BZUUAFTSALJYLANCNFSM4PWWZ3IQ.