Keith Weintraub
2012-Mar-01 02:41 UTC
[R] Create a function "automatically" from lm formula and coefficients?
I hope the subject says it all. I want to be able to use an lm object and the associated coefficients to create function that can produce "expected" "y" values given inputs. Thanks, KW -- [[alternative HTML version deleted]]
Frank Harrell
2012-Mar-01 02:50 UTC
[R] Create a function "automatically" from lm formula and coefficients?
require(rms) f <- ols(y ~ rcs(age,4)*sex + blood.pressure + rcs(height,5)) latex(f) # typeset algebraic form of model Function(f) # create an R function that computes Y hat Frank ----- Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Create-a-function-automatically-from-lm-formula-and-coefficients-tp4433854p4433870.html Sent from the R help mailing list archive at Nabble.com.
Pascal Oettli
2012-Mar-01 02:53 UTC
[R] Re : Create a function "automatically" from lm formula and coefficients?
Hi Keith, Do you mean as "predict.lm" can do? Regards, Pascal ________________________________ De?: Keith Weintraub <kw1958 at gmail.com> ??: r-help at r-project.org Envoy? le : Jeudi 1 mars 2012 11h41 Objet?: [R] Create a function "automatically" from lm formula and coefficients? I hope the subject says it all. I want to be able to use an lm object and the associated coefficients to create? function that can produce "expected" "y" values given inputs. Thanks, KW -- ??? [[alternative HTML version deleted]] ______________________________________________ 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.
Frank Harrell
2012-Mar-01 13:39 UTC
[R] Re : Create a function "automatically" from lm formula and coefficients?
yes, e.g. require(rms) f <- ols( ) # ols is a wrapper for lm g <- Function(f) g(age=30) # get predicted mean at age=30 and defaults for other variables (medians & modes) Frank Pascal Oettli-2 wrote> > Hi Keith, > > Do you mean as "predict.lm" can do? > > Regards, > Pascal > > > ________________________________ > De?: Keith Weintraub <kw1958@> > ??: r-help@ > Envoy? le : Jeudi 1 mars 2012 11h41 > Objet?: [R] Create a function "automatically" from lm formula and > coefficients? > > I hope the subject says it all. > > I want to be able to use an lm object and the associated coefficients to > create? function that can produce "expected" "y" values given inputs. > > Thanks, > KW > > -- > > > ??? [[alternative HTML version deleted]] > > ______________________________________________ > R-help@ 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@ 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. >----- Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Create-a-function-automatically-from-lm-formula-and-coefficients-tp4433854p4434981.html Sent from the R help mailing list archive at Nabble.com.