[R] problems using the thin plate spline method
R. Michael Weylandt <michael.weylandt@gmail.com>
michael.weylandt at gmail.com
Mon Dec 5 14:04:36 CET 2011
Your data was scrubbed by the server. Use dput() to create a plain text representation of dat you can put in the body of the email.
Michael
On Dec 5, 2011, at 6:54 AM, Mintewab Bezabih <Mintewab.Bezabih at economics.gu.se> wrote:
> Dear Jeff and R users,
>
> Thanks Jeff.
>
> Your first plot suggestion worked. And when I stick dat$x1, dat$x2,dat$y, tpsfit seems to work as well. But it gives me a new error message
>
> tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled")
>
> Warning message:
> In gcv.Krig(out, nstep.cv = nstep.cv, verbose = verbose, cost = out$cost, :
> Value of pure error estimate is outside possible range
>
> Then I get error messages for the subsequent lines as well.
>
> I have now attached the data. And here is the full code I am trying to run.
>
>
> dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",")
> names(dat) <- c("x1", "x2", "y")
> library(fields)
> plot (dat)
>
> #load the fields package (containing Tps) and fit a thin plate spline
> tpsfit <- Tps(cbind(dat$x1, dat$x2), dat$y, scale.type="unscaled")
>
> #predict the thin plate spline on the fine grid and plot the fitting
> ngrid <- length(xf); grid <- cbind(rep(xf, ngrid), rep(xf, rep(ngrid, ngrid)))
> out.p1 <- predict(tpsfit, grid)
>
>
> persp(xf, xf, matrix(out.p1, ngrid, ngrid, byrow=F), theta=130, phi=20,
> expand=0.45, xlab="x1", ylab="x2", zlab="y", xlim=c(0,1), ylim=c(0,1),
> zlim=range(zf), ticktype="detailed", scale=F, main="gcv fitting")
>
> Many thanks once again.
>
> regards
> mintewab
>
>
>
> Från: Jeff Newmiller [jdnewmil at dcn.davis.ca.us]
> Skickat: den 5 december 2011 12:39
> Till: Mintewab Bezabih; Sarah Goslee
> Kopia: r-help at r-project.org
> Ämne: Re: [R] problems using the thin plate spline method
>
> Try
>
> plot( dat$x1, dat$y )
>
> or
>
> plot( x1, y, data=dat )
>
> Note that your example is still not reproducible because you have not supplied the data or a shortened version of your data for us to work with. Also, your problem is not with thin plates but with plot, and reading the help for that function by typing
>
> ?plot
>
> at the R command line would have provided you with more examples and usage info on how to get around this problem.
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> Mintewab Bezabih <Mintewab.Bezabih at economics.gu.se> wrote:
>
>> Dear Sarah and R users,
>>
>> Sorry again for not being explicit enough. Here is my full problem
>>
>>
>> dat <- read.table("E:/thin plate/thin plate.csv", header=T, sep=",")
>> dat
>> names(dat) <- c("x1", "x2", "y")
>> library(fields)
>> plot (dat)
>>
>> #load the fields package (containing Tps) and fit a thin plate spline
>> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled")
>>
>> What I meant when I said the graph works is when I do plot(dat) it does
>> plot of all my three variables. If I do plot(x1,y), though, I get the
>> 'object x1 not found' error message.
>>
>> Same when I do the next line tpsfit <- Tps(cbind(x1, x2), y,
>> scale.type="unscaled"). I get the same error message.
>>
>> I tried your suggestion of checking str(x1) and I get the same error
>> message (object x1 not found).
>> I also typed ls() and I get "dat" after that command.
>>
>> I followed the r tutorial guide to read my data and I am following the
>> r tutorial to guide me to apply the thin plate spline method.
>>
>> Regards,
>>
>> Mintewab
>> ________________________________________
>> Från: Sarah Goslee [sarah.goslee at gmail.com]
>> Skickat: den 4 december 2011 15:21
>> Till: Mintewab Bezabih
>> Kopia: r-help at r-project.org
>> Ämne: Re: [R] problems using the thin plate spline method
>>
>> Hello,
>>
>> On Sun, Dec 4, 2011 at 8:08 AM, Mintewab Bezabih
>> <Mintewab.Bezabih at economics.gu.se> wrote:
>>> Dear R users and Jeff,
>>>
>>> Sorry for not being quite explicit in my earlier message.
>>
>> And you are still not explicit. We have no idea what you've done.
>>
>>> My main problem is while my data seem to be read into R well (I
>> manage to graph them and all), I cannot get the following line to work.
>>>
>>> tpsfit <- Tps(cbind(x1, x2), y, scale.type="unscaled")
>>>
>>> and I get the following error message
>>>
>>> Error in as.matrix(x) :
>>> error in evaluating the argument 'x' in selecting a method for
>> function 'as.matrix': Error: object 'x1' not found
>>
>> I'd have to guess that there's no object x1. What does ls() tell you?
>> str(x1)?
>>
>> What do your data look like? You were already given instructions on how
>> to
>> include sample data to construct a reproducible example. You said that
>> graphing your data worked; how did you do so?
>>
>> The posting guide and the advice you were already given were both
>> offered for a reason. The querent needs to do the work of formulating
>> an understandable and answerable question.
>>
>> Sarah
>>
>>> thanks for help
>>> minti
>>> ________________________________________
>>> Från: Jeff Newmiller [jdnewmil at dcn.davis.ca.us]
>>> Skickat: den 3 december 2011 17:45
>>> Till: Mintewab Bezabih; r-help at r-project.org
>>> Ämne: Re: [R] problems using the thin plate spline method
>>>
>>> I can tell that you are puzzled and confused. Unfortunately, I am not
>> psychic, so I cannot tell what you did, and therefore cannot tell where
>> you went astray.
>>>
>>> The solution is for you to read the posting guide mentioned at the
>> bottom of every R-help message. Spend a little time to create a small
>> bit of data like yours if your actual data is large (subset and dput
>> are useful for this). Remember to include the output of sessionInfo,
>> and so on. Many times you are likely to find the answer yourself by
>> going through these steps, but they are essential for communication.
>>>
>>> Good luck.
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> Mintewab Bezabih <Mintewab.Bezabih at economics.gu.se> wrote:
>>>
>>>> Dear R users,
>>>>
>>>> I am a beginner in R trying to apply the thin plate spline method to
>> my
>>>> climate data. I used the example in R to do so, and the lines seem to
>>>> run fine ( I am not getting errors) but I am not getting any output
>> in
>>>> the form of graph or anything. I got a warning message saying that
>>>> 'surface extends beyond box'.
>>>>
>>>> Any help is much appreciated.
>>>> thanks
>>>> minti
>>
>>
>> --
>> Sarah Goslee
>> http://www.functionaldiversity.org
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list