Hi all, suppose I've got a vector y with some data (from a repeated measure design) observed given the conditions in f1 and f2. I've got a model with two unknown fix constants a and b which tries to predict y with respect to the values in f1 and f2. Here is an exsample # "data" y <- c(runif(10, -1,0), runif(10,0,1)) # f1 f1 <- rep(c(-1.4, 1.4), rep(10,2)) # f2 f2 <- rep(c(-.5, .5), rep(10,2)) Suppose my simple model looks like y = a/f1 + b*f2 Is there a function in R which can compute the estimates for a and b? And is it possible to test the model, eg how "good" the fits of the model are? Thanks, Sven
That's the linear model lm(y ~ I(1/f1) + f2), so yes, yes and fuller answers can be found in most of the books and guides mentioned in R's FAQ. Note that how `good' the fit is will have to be relative, unless you really can assume a uniform error with range 1, when you could do a maximum-likelihood fit (and watch out for the non-standard distribution theory). On 27 Aug 2003, Sven Garbade wrote:> Hi all, > > suppose I've got a vector y with some data (from a repeated measure > design) observed given the conditions in f1 and f2. I've got a model > with two unknown fix constants a and b which tries to predict y with > respect to the values in f1 and f2. Here is an exsample > > # "data" > y <- c(runif(10, -1,0), runif(10,0,1)) > # f1 > f1 <- rep(c(-1.4, 1.4), rep(10,2)) > # f2 > f2 <- rep(c(-.5, .5), rep(10,2)) > > Suppose my simple model looks like > > y = a/f1 + b*f2> Is there a function in R which can compute the estimates for a and b? > And is it possible to test the model, eg how "good" the fits of the > model are?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Peter Dalgaard BSA
2003-Aug-27 16:17 UTC
[R] How to test a model with two unkown constants
Sven Garbade <garbade at psy.uni-muenchen.de> writes:> Hi all, > > suppose I've got a vector y with some data (from a repeated measure > design) observed given the conditions in f1 and f2. I've got a model > with two unknown fix constants a and b which tries to predict y with > respect to the values in f1 and f2. Here is an exsample > > # "data" > y <- c(runif(10, -1,0), runif(10,0,1)) > # f1 > f1 <- rep(c(-1.4, 1.4), rep(10,2)) > # f2 > f2 <- rep(c(-.5, .5), rep(10,2)) > > Suppose my simple model looks like > > y = a/f1 + b*f2 > > Is there a function in R which can compute the estimates for a and b? > And is it possible to test the model, eg how "good" the fits of the > model are?f2 and 1/f1 are exactly collinear, so no, not in R, nor any other way. Apart from that, the model is linear in a and b so lm() can fit it (with different f1 and f2) if you're not too squeamish about the error distribution. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907