Re: [R] Test individual slope for each factor level in ANCOVA

2017-03-16 Thread li li
Hi John. Thanks much for your help. It is great to know this.
  Hanna

2017-03-16 8:02 GMT-04:00 Fox, John :

> Dear Hanna,
>
> You can test the slope in each non-reference group as a linear hypothesis.
> You didn’t make the data available for your example, so here’s an example
> using the linearHypothesis() function in the car package with the Moore
> data set in the same package:
>
> - - - snip - - -
>
> > library(car)
> > mod <- lm(conformity ~ fscore*partner.status, data=Moore)
> > summary(mod)
>
> Call:
> lm(formula = conformity ~ fscore * partner.status, data = Moore)
>
> Residuals:
> Min  1Q  Median  3Q Max
> -7.5296 -2.5984 -0.4473  2.0994 12.4704
>
> Coefficients:
>   Estimate Std. Error t value Pr(>|t|)
> (Intercept)   20.793483.26273   6.373 1.27e-07 ***
> fscore-0.151100.07171  -2.107  0.04127 *
> partner.statuslow-15.534084.40045  -3.530  0.00104 **
> fscore:partner.statuslow   0.261100.09700   2.692  0.01024 *
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> Residual standard error: 4.562 on 41 degrees of freedom
> Multiple R-squared:  0.2942,Adjusted R-squared:  0.2426
> F-statistic: 5.698 on 3 and 41 DF,  p-value: 0.002347
>
> > linearHypothesis(mod, "fscore + fscore:partner.statuslow")
> Linear hypothesis test
>
> Hypothesis:
> fscore  + fscore:partner.statuslow = 0
>
> Model 1: restricted model
> Model 2: conformity ~ fscore * partner.status
>
>   Res.DfRSS Df Sum of Sq  F  Pr(>F)
> 1 42 912.45
> 2 41 853.42  159.037 2.8363 0.09976 .
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> - - - snip - - -
>
> In this case, there are just two levels for partner.status, but for a
> multi-level factor you can simply perform more than one test.
>
>
> I hope this helps,
>
>  John
>
> -
> John Fox, Professor
> McMaster University
> Hamilton, Ontario, Canada
> Web: http://socserv.mcmaster.ca/jfox/
>
>
>
>
> On 2017-03-15, 9:43 PM, "R-help on behalf of li li"
>  wrote:
>
> >Hi all,
> >   Consider the data set where there are a continuous response variable, a
> >continuous predictor "weeks" and a categorical variable "region" with five
> >levels "a", "b", "c",
> >"d", "e".
> >  I fit the ANCOVA model as follows. Here the reference level is region
> >"a"
> >and there are 4 dummy variables. The interaction terms (in red below)
> >represent the slope
> >difference between each region and  the baseline region "a" and the
> >corresponding p-value is for testing whether this slope difference is
> >zero.
> >Is there a way to directly test whether the slope corresponding to each
> >individual factor level is 0 or not, instead of testing the slope
> >difference from the baseline level?
> >  Thanks very much.
> >  Hanna
> >
> >
> >
> >
> >
> >
> >> mod <- lm(response ~ weeks*region,data)> summary(mod)
> >Call:
> >lm(formula = response ~ weeks * region, data = data)
> >
> >Residuals:
> > Min   1Q   Median   3Q  Max
> >-0.19228 -0.07433 -0.01283  0.04439  0.24544
> >
> >Coefficients:
> >Estimate Std. Error t value Pr(>|t|)
> >(Intercept)1.2105556  0.0954567  12.682  1.2e-14 ***
> >weeks -0.021  0.0147293  -1.4480.156
> >regionb   -0.0257778  0.1349962  -0.1910.850
> >regionc   -0.034  0.1349962  -0.2550.800
> >regiond   -0.075  0.1349962  -0.5590.580
> >regione   -0.148  0.1349962  -1.0980.280weeks:regionb
> >-0.0007222  0.0208304  -0.0350.973
> >weeks:regionc -0.0017778  0.0208304  -0.0850.932
> >weeks:regiond  0.003  0.0208304   0.1440.886
> >weeks:regione  0.0301667  0.0208304   1.4480.156---
> >Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> >
> >Residual standard error: 0.1082 on 35 degrees of freedom
> >Multiple R-squared:  0.2678,   Adjusted R-squared:  0.07946
> >F-statistic: 1.422 on 9 and 35 DF,  p-value: 0.2165
> >
> >   [[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.
>
>

[[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] Test individual slope for each factor level in ANCOVA

2017-03-16 Thread Fox, John
Dear Hanna,

You can test the slope in each non-reference group as a linear hypothesis.
You didn’t make the data available for your example, so here’s an example
using the linearHypothesis() function in the car package with the Moore
data set in the same package:

- - - snip - - -

> library(car)
> mod <- lm(conformity ~ fscore*partner.status, data=Moore)
> summary(mod)

Call:
lm(formula = conformity ~ fscore * partner.status, data = Moore)

Residuals:
Min  1Q  Median  3Q Max
-7.5296 -2.5984 -0.4473  2.0994 12.4704

Coefficients:
  Estimate Std. Error t value Pr(>|t|)
(Intercept)   20.793483.26273   6.373 1.27e-07 ***
fscore-0.151100.07171  -2.107  0.04127 *
partner.statuslow-15.534084.40045  -3.530  0.00104 **
fscore:partner.statuslow   0.261100.09700   2.692  0.01024 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 4.562 on 41 degrees of freedom
Multiple R-squared:  0.2942,Adjusted R-squared:  0.2426
F-statistic: 5.698 on 3 and 41 DF,  p-value: 0.002347

> linearHypothesis(mod, "fscore + fscore:partner.statuslow")
Linear hypothesis test

Hypothesis:
fscore  + fscore:partner.statuslow = 0

Model 1: restricted model
Model 2: conformity ~ fscore * partner.status

  Res.DfRSS Df Sum of Sq  F  Pr(>F)
1 42 912.45
2 41 853.42  159.037 2.8363 0.09976 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

- - - snip - - -

In this case, there are just two levels for partner.status, but for a
multi-level factor you can simply perform more than one test.


I hope this helps,

 John

-
John Fox, Professor
McMaster University
Hamilton, Ontario, Canada
Web: http://socserv.mcmaster.ca/jfox/




On 2017-03-15, 9:43 PM, "R-help on behalf of li li"
 wrote:

>Hi all,
>   Consider the data set where there are a continuous response variable, a
>continuous predictor "weeks" and a categorical variable "region" with five
>levels "a", "b", "c",
>"d", "e".
>  I fit the ANCOVA model as follows. Here the reference level is region
>"a"
>and there are 4 dummy variables. The interaction terms (in red below)
>represent the slope
>difference between each region and  the baseline region "a" and the
>corresponding p-value is for testing whether this slope difference is
>zero.
>Is there a way to directly test whether the slope corresponding to each
>individual factor level is 0 or not, instead of testing the slope
>difference from the baseline level?
>  Thanks very much.
>  Hanna
>
>
>
>
>
>
>> mod <- lm(response ~ weeks*region,data)> summary(mod)
>Call:
>lm(formula = response ~ weeks * region, data = data)
>
>Residuals:
> Min   1Q   Median   3Q  Max
>-0.19228 -0.07433 -0.01283  0.04439  0.24544
>
>Coefficients:
>Estimate Std. Error t value Pr(>|t|)
>(Intercept)1.2105556  0.0954567  12.682  1.2e-14 ***
>weeks -0.021  0.0147293  -1.4480.156
>regionb   -0.0257778  0.1349962  -0.1910.850
>regionc   -0.034  0.1349962  -0.2550.800
>regiond   -0.075  0.1349962  -0.5590.580
>regione   -0.148  0.1349962  -1.0980.280weeks:regionb
>-0.0007222  0.0208304  -0.0350.973
>weeks:regionc -0.0017778  0.0208304  -0.0850.932
>weeks:regiond  0.003  0.0208304   0.1440.886
>weeks:regione  0.0301667  0.0208304   1.4480.156---
>Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
>Residual standard error: 0.1082 on 35 degrees of freedom
>Multiple R-squared:  0.2678,   Adjusted R-squared:  0.07946
>F-statistic: 1.422 on 9 and 35 DF,  p-value: 0.2165
>
>   [[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.

__
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.

[R] Test individual slope for each factor level in ANCOVA

2017-03-15 Thread li li
Hi all,
   Consider the data set where there are a continuous response variable, a
continuous predictor "weeks" and a categorical variable "region" with five
levels "a", "b", "c",
"d", "e".
  I fit the ANCOVA model as follows. Here the reference level is region "a"
and there are 4 dummy variables. The interaction terms (in red below)
represent the slope
difference between each region and  the baseline region "a" and the
corresponding p-value is for testing whether this slope difference is zero.
Is there a way to directly test whether the slope corresponding to each
individual factor level is 0 or not, instead of testing the slope
difference from the baseline level?
  Thanks very much.
  Hanna






> mod <- lm(response ~ weeks*region,data)> summary(mod)
Call:
lm(formula = response ~ weeks * region, data = data)

Residuals:
 Min   1Q   Median   3Q  Max
-0.19228 -0.07433 -0.01283  0.04439  0.24544

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)1.2105556  0.0954567  12.682  1.2e-14 ***
weeks -0.021  0.0147293  -1.4480.156
regionb   -0.0257778  0.1349962  -0.1910.850
regionc   -0.034  0.1349962  -0.2550.800
regiond   -0.075  0.1349962  -0.5590.580
regione   -0.148  0.1349962  -1.0980.280weeks:regionb
-0.0007222  0.0208304  -0.0350.973
weeks:regionc -0.0017778  0.0208304  -0.0850.932
weeks:regiond  0.003  0.0208304   0.1440.886
weeks:regione  0.0301667  0.0208304   1.4480.156---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1082 on 35 degrees of freedom
Multiple R-squared:  0.2678,Adjusted R-squared:  0.07946
F-statistic: 1.422 on 9 and 35 DF,  p-value: 0.2165

[[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.