# Re: [R] : Model formula question

From: David Firth <d.firth_at_warwick.ac.uk>
Date: Wed 01 Feb 2006 - 21:28:07 EST

On Wednesday 01 February 2006 02:37, maneesh deshpande wrote:
> Hi,
>
> I have a data set with a continuous predictor X, a factor
> A and a continuous dependent
> variable Y.
> I am trying to build a linear model of the form:
>
> Y = (b0 + b1*X1)*B(A)
>
> where B(A) is a constant for each level of the factor A.
> I am not quite sure how to formulate the appropriate
> model formula. If I write:
>
> Y ~ ( 1 + X)/A
>
> , I get estimates for as many constants and slopes as the
> number of levels of A.

Yes, that's right: the / symbol has a special (non-arithmetic) meaning when used like this in a model formula. See for example p151 onwards in the reference that is given by ?formula.

> What I really need is an overall multiplicative constant
> which depends on the factor A.

The gnm (generalized nonlinear models) package has facilities for this. The model above could be specified there as

Y ~ -1 + Mult(X, -1 + A)
(where the first "-1" removes the intercept, and the second one says to estimate a separate multiplier for each level of A rather than using contrasts in A). Or, if you want to constrain all of your multipliers to have the same sign, you can use

Y ~ -1 + Mult(X, Exp(-1 + A))
(note the capital E there!).

It is unclear to me that using the *same* set of multipliers for both intercept and slope will typically be the right thing to do, though. It would not, for example, be invariant to transformation of X to X-c, with c constant. That is to say, your X variable needs to be on a scale for which the zero value has a special meaning, in order to allow the above model to make sense. But presumably you have thought about this already.

Hoping that helps,
David

```--
Professor David Firth
http://www.warwick.ac.uk/go/dfirth

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help