simple interactions

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

simple interactions

Therneau, Terry M., Ph.D.
I'd like to get interaction terms in a model to be in another form.  Namely, suppose I had
variables age and group, the latter a factor with levels A, B, C, with  age * group in the
model.  What I would like are the variables "age:group=A", "age:group=B" and
"age:group=C"  (and group itself of course).  The coefficients of the model will then be
the age effect in group A, the age effect in group B and the age effect in C rather than
the standard ones of an overall age effect followed by contrasts.  These is often a better
format for tables in a publication.

Yes, I can reconstruct these from the original fit, but I have a lot of variables for
several models and it would be easier to have an automatic form.  I suspect that there is
an easy answer, but I don't see it.

Terry Therneau

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: simple interactions

Thierry Onkelinx
Dear Terry,

Does fitting group + age:group instead of age*group solves your problem?

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-04-15 13:58 GMT+02:00 Therneau, Terry M., Ph.D. <[hidden email]>:

> I'd like to get interaction terms in a model to be in another form.
> Namely, suppose I had variables age and group, the latter a factor with
> levels A, B, C, with  age * group in the model.  What I would like are the
> variables "age:group=A", "age:group=B" and "age:group=C"  (and group itself
> of course).  The coefficients of the model will then be the age effect in
> group A, the age effect in group B and the age effect in C rather than the
> standard ones of an overall age effect followed by contrasts.  These is
> often a better format for tables in a publication.
>
> Yes, I can reconstruct these from the original fit, but I have a lot of
> variables for several models and it would be easier to have an automatic
> form.  I suspect that there is an easy answer, but I don't see it.
>
> Terry Therneau
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: simple interactions

Achim Zeileis-4
In reply to this post by Therneau, Terry M., Ph.D.
Try using
   ~ group/age
or even
   ~ 0 + group/age

Both have all three group-specific slopes but differ with respect to the
intercept codings. The latter has three group-specific intercepts as well.
But the former has an intercept corresponding to the reference group A and
then the usual treatment contrasts for group B and C (i.e., intercept
differences).

IIRC then I found the discussion of these contrasts and nested codings in
the MASS book very useful.

On Fri, 15 Apr 2016, Therneau, Terry M., Ph.D. wrote:

> I'd like to get interaction terms in a model to be in another form.  Namely,
> suppose I had variables age and group, the latter a factor with levels A, B,
> C, with  age * group in the model.  What I would like are the variables
> "age:group=A", "age:group=B" and "age:group=C"  (and group itself of course).
> The coefficients of the model will then be the age effect in group A, the age
> effect in group B and the age effect in C rather than the standard ones of an
> overall age effect followed by contrasts.  These is often a better format for
> tables in a publication.
>
> Yes, I can reconstruct these from the original fit, but I have a lot of
> variables for several models and it would be easier to have an automatic
> form.  I suspect that there is an easy answer, but I don't see it.
>
> Terry Therneau
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: simple interactions

Therneau, Terry M., Ph.D.
In reply to this post by Thierry Onkelinx
I was right that there is an easy answer!

Thanks for the 3 quick answers, all three correct and useful.

Terry Therneau


On 04/15/2016 07:15 AM, Thierry Onkelinx wrote:

> Dear Terry,
>
> Does fitting group + age:group instead of age*group solves your problem?
>
> Best regards,
>
> ir. Thierry Onkelinx
>
>> 2016-04-15 13:58 GMT+02:00 Therneau, Terry M., Ph.D. <[hidden email]
> <mailto:[hidden email]>>:
>
>     I'd like to get interaction terms in a model to be in another form. Namely, suppose I
>     had variables age and group, the latter a factor with levels A, B, C, with  age *
>     group in the model.  What I would like are the variables "age:group=A", "age:group=B"
>     and "age:group=C"  (and group itself of course).  The coefficients of the model will
>     then be the age effect in group A, the age effect in group B and the age effect in C
>     rather than the standard ones of an overall age effect followed by contrasts.  These
>     is often a better format for tables in a publication.
>
>     Yes, I can reconstruct these from the original fit, but I have a lot of variables for
>     several models and it would be easier to have an automatic form.  I suspect that there
>     is an easy answer, but I don't see it.
>
>     Terry Therneau

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: simple interactions

Martin Maechler
In reply to this post by Therneau, Terry M., Ph.D.
>>>>> Therneau, Terry M , Ph D <[hidden email]>
>>>>>     on Fri, 15 Apr 2016 06:58:22 -0500 writes:

    > I'd like to get interaction terms in a model to be in
    > another form.  Namely, suppose I had variables age and
    > group, the latter a factor with levels A, B, C, with age *
    > group in the model.  What I would like are the variables
    > "age:group=A", "age:group=B" and "age:group=C" (and group
    > itself of course).  The coefficients of the model will
    > then be the age effect in group A, the age effect in group
    > B and the age effect in C rather than the standard ones of
    > an overall age effect followed by contrasts.  These is
    > often a better format for tables in a publication.

Did you try  to use  one of the good old

   dummy.coef()

or

   model.tables()

Functions?
Please use R  3.2.4 or newer, notably for dummy.coef() which was
improved (made more generally working) for R 3.2.4, notably
thanks to my colleague Werner Stahel.

Best regards,
Martin

--
Martin Maechler, ETH Zurich

 

    > Yes, I can reconstruct these from the original fit, but I
    > have a lot of variables for several models and it would be
    > easier to have an automatic form.  I suspect that there is
    > an easy answer, but I don't see it.

    > Terry Therneau

    > ______________________________________________
    > [hidden email] mailing list -- To UNSUBSCRIBE and
    > more, see 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.