[R] Variable name as string

Peter Dalgaard pdalgd at gmail.com
Sun Oct 17 14:19:31 CEST 2010


On 10/17/2010 11:25 AM, Jan private wrote:
> So here is the next version.
> 
> Why does the intercept needs lower.tail=TRUE to give the same result as
> summary() for value=0?

It doesn't.

Or rather: For all coefficients, lower/upper tail depends on the _sign_
of t, so presumably you have a negative intercept in this particular
data set.

The more traditional way is 2*pt(-abs(t), n).

> 
> # See Verzani, simpleR (pdf), p. 80
> coeff.test <- function(lm.result, idx, value) {
>   # idx = 1 is the intercept, idx>1 the other coefficients
>   # null hypothesis: coeff = value
>   # alternative hypothesis: coeff != value
>   coeff <- coefficients(lm.result)[idx]
>   SE <- coefficients(summary(lm.result))[idx,"Std. Error"]
>   n <- df.residual(lm.result)
>   t <- (coeff - value )/SE
>   if (idx == 1) {
>     2 * pt(t,n,lower.tail=TRUE) # times two because problem is two-sided
>   } else {
>     2 * pt(t,n,lower.tail=FALSE)
>   }
> }
> 
> 


-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list