Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inference about Slope coefficient in R

Tags:

r

lm

stat

By default lm summary test slope coefficient equal to zero. My question is very basic. I want to know how to test slope coefficient equal to non-zero value. One approach could be to use confint but this does not provide p-value. I also wonder how to do one-sided test with lm.

ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
summary(lm.D9)

Call:
lm(formula = weight ~ group)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.0710 -0.4938  0.0685  0.2462  1.3690 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   5.0320     0.2202  22.850 9.55e-15 ***
groupTrt     -0.3710     0.3114  -1.191    0.249    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.6964 on 18 degrees of freedom
Multiple R-squared: 0.07308,    Adjusted R-squared: 0.02158 
F-statistic: 1.419 on 1 and 18 DF,  p-value: 0.249 


confint(lm.D9)
              2.5 %    97.5 %
(Intercept)  4.56934 5.4946602
groupTrt    -1.02530 0.2833003

Thanks for your time and effort.

like image 850
MYaseen208 Avatar asked Dec 28 '22 11:12

MYaseen208


1 Answers

as @power says, you can do by your hand. here is an example:

> est <- summary.lm(lm.D9)$coef[2, 1]
> se <- summary.lm(lm.D9)$coef[2, 2]
> df <- summary.lm(lm.D9)$df[2]
> 
> m <- 0
> 2 * abs(pt((est-m)/se, df))
[1] 0.2490232
> 
> m <- 0.2
> 2 * abs(pt((est-m)/se, df))
[1] 0.08332659

and you can do one-side test by omitting 2*.

UPDATES

here is an example of two-side and one-side probability:

> m <- 0.2
> 
> # two-side probability
> 2 * abs(pt((est-m)/se, df))
[1] 0.08332659
> 
> # one-side, upper (i.e., greater than 0.2)
> pt((est-m)/se, df, lower.tail = FALSE)
[1] 0.9583367
> 
> # one-side, lower (i.e., less than 0.2)
> pt((est-m)/se, df, lower.tail = TRUE)
[1] 0.0416633

note that sum of upper and lower probabilities is exactly 1.

like image 199
kohske Avatar answered Jan 11 '23 23:01

kohske