Re: [R] I am struggling with contrasts

2020-03-10 Thread Berwin A Turlach
G'day all,

On Tue, 10 Mar 2020 11:07:13 +
"Viechtbauer, Wolfgang (SP)"
 wrote:

> The linearHypothesis() function from the 'car' package does this.

The function glht() in the 'multcomp' package should also be able to do
this.  

The 'emmeans' package might also be useful.

Will be off-line for a while now, but might look at the example again
and how to do it with 'multcomp' or 'emmeans' later.

Cheers,

Berwin

__
R-help@r-project.org 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.


Re: [R] I am struggling with contrasts

2020-03-10 Thread Viechtbauer, Wolfgang (SP)
Dear John,

The linearHypothesis() function from the 'car' package does this.

>From the help file: "The value of the linear hypothesis and its covariance 
>matrix are returned respectively as "value" and "vcov" attributes of the 
>object (but not printed)." For  a single linear combination, vcov will be a 
>single value and its square-root the SE.

Best,
Wolfgang

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sorkin, John
Sent: Tuesday, 10 March, 2020 11:51
To: peter dalgaard; Berwin A Turlach
Cc: r-help@r-project.org (r-help@r-project.org)
Subject: Re: [R] I am struggling with contrasts

I have not clearly stated my question. I would like to obtain the point 
estimate and SE (or point estimate and 95% CI) of a linear combination of the 
the independent variables included in my regression model. In a simple model 
having a single categorical variable that has two levels (Group1 and Group2) 
obtaining the estimate and its SE (or the estimate and a 95% CI) requires 
knowing the betas produced by the model, the SEs of the betas (which are easily 
obtained) along with the variance covariance of the estimates. I assume that 
the variance covariance matrix can be obtained but working the the matrix is a 
real pain. I am looking for a SIMPLE way to get the point estimate and its SE 
without having to slog though getting all the estimates, their SEs manually 
adding them together and including the covariances.
For example if my model is

rate = group and group has the value 1, I want:

beta rate = beta intercept + beta group
variance rate = variance intercept + variance group + 2*covariance 
(intercept,group)

I suspect I can do this calculation manually, but I would really like to find a 
way that R will do the computation for me.

My regression model is:
fit1 <- glm(HGE ~ Group,family=quasipoisson(link="log"), 
data=dataForR,offset=logFU)

In SAS this can be accomplished using estimate statements; I suspect that is an 
R analogue of the SAS estimate statement, but I don't know that the analogue is 
.

Thank you,

John

Particular thanks are due to Peter Dalgaard, Berwin Turlach, and Mark Leeds who 
responded to my original, not well formulated posting.

Thank you,

John

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

__
R-help@r-project.org 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.


Re: [R] I am struggling with contrasts

2020-03-10 Thread Sorkin, John
I have not clearly stated my question. I would like to obtain the point 
estimate and SE (or point estimate and 95% CI) of a linear combination of the 
the independent variables included in my regression model. In a simple model 
having a single categorical variable that has two levels (Group1 and Group2) 
obtaining the estimate and its SE (or the estimate and a 95% CI) requires 
knowing the betas produced by the model, the SEs of the betas (which are easily 
obtained) along with the variance covariance of the estimates. I assume that 
the variance covariance matrix can be obtained but working the the matrix is a 
real pain. I am looking for a SIMPLE way to get the point estimate and its SE 
without having to slog though getting all the estimates, their SEs manually 
adding them together and including the covariances.
For example if my model is

rate = group and group has the value 1, I want:

beta rate = beta intercept + beta group
variance rate = variance intercept + variance group + 2*covariance 
(intercept,group)

I suspect I can do this calculation manually, but I would really like to find a 
way that R will do the computation for me.

My regression model is:
fit1 <- glm(HGE ~ Group,family=quasipoisson(link="log"), 
data=dataForR,offset=logFU)

In SAS this can be accomplished using estimate statements; I suspect that is an 
R analogue of the SAS estimate statement, but I don't know that the analogue is 
.

Thank you,

John

Particular thanks are due to Peter Dalgaard, Berwin Turlach, and Mark Leeds who 
responded to my original, not well formulated posting.



Thank you,

John





John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)



From: peter dalgaard 
Sent: Tuesday, March 10, 2020 5:07 AM
To: Berwin A Turlach 
Cc: Sorkin, John ; r-help@r-project.org 
(r-help@r-project.org) 
Subject: Re: [R] I am struggling with contrasts

Yes. Contrasts, by definition, represents between-group differences, so cannot 
yield individual group levels. The closest you get is that the _intercept_ is 
the level of the base group in treatment contrasts, and relevel() will allow 
you to change the base level.

-pd

> On 10 Mar 2020, at 04:06 , Berwin A Turlach  wrote:
>
> G'day John,
>
> On Tue, 10 Mar 2020 01:42:46 +
> "Sorkin, John"  wrote:
>
>> I am running a Poisson regression with a single outcome variable,
>> HGE, and a single independent variable, a factor, Group which can be
>> one of two values, Group1, or Group2. I am trying to define contrasts
>> that will give me the values of my outcome variable (HGE) when
>> group=Group1 and when group=Group2.
>
> Not sure what you mean, but I am suspecting you are after this output:
>
> R> fit0 <- glm(HGE ~ Group - 1,family=poisson,data=dataForR,offset=logFU)
> R> summary(fit0)
>
> Cheers,
>
>Berwin
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=02%7C01%7C%7C4b9ea7f815e0494abf0908d7c4d2770c%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637194280543093844sdata=QFyKBzxZfkXAjASSUYsSnMJ1CiZIjXDK6JEgKHrV5vg%3Dreserved=0
> PLEASE do read the posting guide 
> https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.htmldata=02%7C01%7C%7C4b9ea7f815e0494abf0908d7c4d2770c%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637194280543093844sdata=pf%2BQVOSaoGq5HwJ1QjMawCArFC1yjpG9yL%2Fs5dv5wJw%3Dreserved=0
> and provide commented, minimal, self-contained, reproducible code.

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com










[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] I am struggling with contrasts

2020-03-10 Thread peter dalgaard
Yes. Contrasts, by definition, represents between-group differences, so cannot 
yield individual group levels. The closest you get is that the _intercept_ is 
the level of the base group in treatment contrasts, and relevel() will allow 
you to change the base level.

-pd

> On 10 Mar 2020, at 04:06 , Berwin A Turlach  wrote:
> 
> G'day John,
> 
> On Tue, 10 Mar 2020 01:42:46 +
> "Sorkin, John"  wrote:
> 
>> I am running a Poisson regression with a single outcome variable,
>> HGE, and a single independent variable, a factor, Group which can be
>> one of two values, Group1, or Group2. I am trying to define contrasts
>> that will give me the values of my outcome variable (HGE) when
>> group=Group1 and when group=Group2. 
> 
> Not sure what you mean, but I am suspecting you are after this output:
> 
> R> fit0 <- glm(HGE ~ Group - 1,family=poisson,data=dataForR,offset=logFU)
> R> summary(fit0)
> 
> Cheers,
> 
>   Berwin
> 
> __
> R-help@r-project.org 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org 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.


Re: [R] I am struggling with contrasts

2020-03-09 Thread Berwin A Turlach
G'day John,

On Tue, 10 Mar 2020 01:42:46 +
"Sorkin, John"  wrote:

> I am running a Poisson regression with a single outcome variable,
> HGE, and a single independent variable, a factor, Group which can be
> one of two values, Group1, or Group2. I am trying to define contrasts
> that will give me the values of my outcome variable (HGE) when
> group=Group1 and when group=Group2. 

Not sure what you mean, but I am suspecting you are after this output:

R> fit0 <- glm(HGE ~ Group - 1,family=poisson,data=dataForR,offset=logFU)
R> summary(fit0)

Cheers,

Berwin

__
R-help@r-project.org 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.