[R] How to obtain the graph of fitted values against one variable after estimation?

David Winsemius dwinsemius at comcast.net
Thu Aug 26 21:04:26 CEST 2010


On Aug 26, 2010, at 2:35 PM, Le Wang wrote:

> Thanks, David.
>
> I did try to use predict() to obtain the graph,

"Try"? How? Code?

( predict() is used to obtain numbers, not to do graphing. )

> but it somehow looks
> different from the one generated by "plot" command.

I have no idea what you actually did. There is no plot method for  
predict objects.

> So, I was
> wondering if there is any way that I can get the one generated by
> "plot" so that I can compare. Thank you.

And, .... what kind of model is "model", anyway? The only  
"plot.errors.method" argument with a value of "asymptotic" I could  
find went with package np. What does class(model) return?

I fear you have not have read the Posting Guide where it is carefully  
explained that one MUST reference packages being used, true? (I  
suppose I should have been alerted by the strange plot argument.)

There is no np.predict listed in help for package=np, but after  
loading package=np, I do see a predict method:  predict.npregression*

So. Why don't you go the full Posting Guide route (and actually  
reading the Posting Guide) and include data and code?

-- 
David,
>
> Le
>
> On Wed, Aug 25, 2010 at 11:15 PM, David Winsemius
> <dwinsemius at comcast.net> wrote:
>>
>> On Aug 25, 2010, at 10:46 PM, Le Wang wrote:
>>
>>> Hi there,
>>>
>>> I have a question regarding the "plot" command after estimation.
>>>
>>> Specifically, I estimate a model, say regressing y on x and z. And
>>> after estimation, I would like to plot the fitted values against x,
>>> but I don't need that for z. The following command always gives two
>>> graphs, for both variables x and z.
>>>
>>> plot.np<-plot(model, plot.errors.method = "asymptotic")
>>>
>>> My question is, what option should I specify in order to get the  
>>> graph
>>> for x only?
>>
>> Pick a constant value for "z" and vary "x" in a dataframe that you  
>> offer to
>> the newdata argument of predict.
>>
>> ?predict
>>
>> Then plot those values versus x.
>>
>>>
>>> I know this is probably a very simple question, but I searched  
>>> around
>>> for a while without any luck. Thank you for your time.
>>
>> --
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>>
>
>
>
> -- 
> ~~~~~~~~~~~~~~~~~~~~~~
> Le Wang, Ph.D
> Population Center
> University of Minnesota
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list