[R] Plot fit of a "generic" function

Gregor Gorjanc gregor.gorjanc at bfro.uni-lj.si
Wed Jul 19 08:27:07 CEST 2006


Yes, that will do.

Thank you Gabor!

Gabor Grothendieck wrote:
> You could plot y vs. fitted(y.lm) where y.lm is the output of lm or
> plot both y and fitted(y.lm) against x on the same chart.
> 
> 
> On 7/18/06, Gregor Gorjanc <gregor.gorjanc at gmail.com> wrote:
>> Hello!
>>
>> Say I have a function, which creates a design matrix i.e.
>>
>> myFunc <- function(x)
>> {
>>  ret <- cbind(x, x*x, x*x*x)
>>  colnames(ret) <- 1:ncol(ret)
>>  return(ret)
>> }
>>
>> n <- 200
>> x <- runif(n=n, min=0, max=100)
>> y <- myFunc(x) %*% c(1, 0.2, -0.0002) +  rnorm(n=n, sd=100)
>>
>> then I can use this in formulae as here
>>
>> (fit <- lm(y ~ myFunc(x)))
>>
>> Now I would like to plot data and fitted function on the plot, but I do
>> not want to access each parameter estimate from object "fit" i.e. I
>> would like to use something similar to abline for linear regression but
>> in a generic way. Is there anything similar to my case?
>>
>> plot(y=y, x=x)
>>
>> ???plotMyFunc???
>>
>> Thanks!
>>
>> -- 
>> Lep pozdrav / With regards,
>>    Gregor Gorjanc
>>
>> ----------------------------------------------------------------------
>> University of Ljubljana     PhD student
>> Biotechnical Faculty
>> Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
>> Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si
>>
>> SI-1230 Domzale             tel: +386 (0)1 72 17 861
>> Slovenia, Europe            fax: +386 (0)1 72 17 888
>>
>> ----------------------------------------------------------------------
>> "One must learn by doing the thing; for though you think you know it,
>>  you have no certainty until you try." Sophocles ~ 450 B.C.
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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.
>>


-- 
Lep pozdrav / With regards,
    Gregor Gorjanc

----------------------------------------------------------------------
University of Ljubljana     PhD student
Biotechnical Faculty
Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si

SI-1230 Domzale             tel: +386 (0)1 72 17 861
Slovenia, Europe            fax: +386 (0)1 72 17 888

----------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
 you have no certainty until you try." Sophocles ~ 450 B.C.



More information about the R-help mailing list