PaulBeales - 5 months ago 42

R Question

I tried this answer

get a surface plot in R

but it hasn't really helped.

I would like to perform a TPS (using Tps from Fields{}) on an XYZ dataframe where xy are co-orinates and z is a thickness. Then I would like to visualise the plot firstly before TPS and then after TPS..? Is this possible.

Then I would like to extract predicted thicknesses for a given set of new xy co-ordinates..?

Please let me know if this is possible

My Dataframe looks like this, dataframe is called LSP:

`time PART MEAS PARTSUB XLOC YLOC`

xxxx 1 1.956 a -3465 -94350

xxxx 1 1.962 a -3465 -53850

xxxx 1 1.951 a 50435 -40350

xxxx 1 1.958 a -57365 -40350

So I tried this:

`LSP.spline <- Tps(LSP[,5:6], LSP$MEAS)`

out.p <- predict.surface(LSP.spline, xy = c(1,2))

plot.surface(out.p, type="p")

But out.p is just NULL..?

so attempting the plot gives me:

`Error in nrow(z) : argument "z" is missing, with no default`

Any help is appreciated.

Paul.

Answer

`predict.surface`

is now an obsolete / deprecated function. Use `predictSurface`

instead.

```
fit<- Tps( BD[,1:4], BD$lnya) # fit surface to data
# evaluate fitted surface for first two
# variables holding other two fixed at median values
out.p<- predictSurface(fit)
surface(out.p, type="C")
```

Thanks for that - how about my second question....how can I extract predicted surface thickness values for a given set of XY locations..?

Use `predict`

function. Have a read on `?predict.Tps`

. For the above example, let's say we want to predict at the first 4 locations in `BD[, 1:4]`

, we can do

```
predict(fit, x = BD[1:4, 1:4])
# [,1]
#[1,] 11.804124
#[2,] 11.804124
#[3,] 8.069056
#[4,] 9.501551
```

In general, pass `x`

a two-column matrix.