[R] How can I get the interpolated data?
David Winsemius
dwinsemius at comcast.net
Sun Dec 21 16:10:56 CET 2008
If you look at the CR.rsm object with str() you will see that it
inherits from the lm class of objects. Therefore the predict.lm method
will be available and if you further look at:
?predict.lm
You see that all you need to do is give it a dataframe that has the
variables that match up with you model terms so this is a minimal
example:
> predict(CR.rsm, newdata=data.frame(x1=84,x2=171))
1
80.58806
To get the entire range that you desire (and which the plotting
function for GSM already produced) you need:
?expand.grid
z <- predict(CR.rsm, expand.grid(x1=seq(86.88,len=21),
x2=seq(175,179,len=21)))
# or
data.frame(expand.grid(x1=seq(86.88,len=21), x2=seq(175,179,len=21)),
z = predict(CR.rsm, expand.grid(x1=seq(86.88,len=21),
x2=seq(175,179,len=21))
)
)
Since you are narrowing the range for your prediction, it's possible
that you already realize that the original example plot was not just
interpolating but also extrapolating considerably beyond the available
data in places. That dataset only had 14 observations and rather
sketchy or non-existent in the extremal regions of the x1 cross x2
space.
I greatly value the ability of the Hmisc/Design packages ability to
restrict estimation and plotting to only those regions where the data
will support estimates. I tried applying the perimeter function in
Harrell's packages to your example, but the plot.Design function
recognized that I was giving it a construct from a different package
and refused to play.
At any rate, HTH.
--
David Winsemius
Heritage Labs
On Dec 21, 2008, at 7:33 AM, pinwheels wrote:
>
> Hello,everybody!
>
> I am a beginner of R.
>
> And I want to ask a question. If anybody would help me, thank you
> very much
> ahead.
> I want to plot something like a response surface, and I find the "rsm"
> package.
>
> Some commands are like this:
>
> #code head
> library(rsm)
> CR = coded.data(ChemReact, x1 ~ Time, x2 ~ Temp)
> CR.rsm = rsm(Yield ~ SO(x1,x2), data = CR)
> summary(CR.rsm)
> contour(CR.rsm,x1~x2)
> #code end
>
> What if I want the data interpolated, what should I do?
> For example:
> There is a data frame like:
>
> xa1<-seq(86,88,len=21)
> xa2<-seq(175,179,len=41)
> z<- ... # referring site(xa1,xa2) from the contour plotted above
>
> or
>
> xa1 xa2 z
> 86 175 ???
> 86.1 175 ???
> ... ... ...
> 86.7 177.3 ???
> ... .... ...
> 88 179 ???
>
> or something alike.
>
> How could I get the z value(???) from the CR.rsm or the plotted
> contour?
> --
> View this message in context: http://www.nabble.com/How-can-I-get-the-interpolated-data--tp21114660p21114660.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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