[R] p value statistic for lm object
Dieter Menne
dieter.menne at menne-biomed.de
Mon Aug 13 10:35:22 CEST 2007
Arjun Bhandari <arb.em <at> adia.ae> writes:
> I conduct a univariate regression with lm function. I would like to get
> the p value for the regression. Is there a method that would enable me to
> extract the p value into a variable.
# From lm docs (Sorry, Annette, for misusing your data)
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)
lm.D90 <- lm(ctl ~ trt)
# let's look if it is in lm..
str(lm.D90)
# mmm.. looks like there are no p-test results
# try summary
sum.lm = summary(lm.D90)
sum.lm
# .. coming closer.
# Colum Pr(>|t|), row trt is what we are looking for
# Let's look into the structure
str(sum.lm)
# $coeffients has the wanted
sum.lm$coefficients
# looks good. We could use this, but better use the accessor function
# Check the documentation, but coef is always a good try
cf = coef(sum.lm)
#now pick the right column
pslope = cf["trt","Pr(>|t|)"]
pslope ##
# Could also use index, but less safe in general, even if the
# "Pr(.." is definitively ugly
cf[2,4]
# In general, the $ approach is not recommened, if there is an
# accessor funtion, use it. The closest (with no p-values) is
confint(lm.D90)
# Which probably tells more than the beloved p-values.
# The better the journal's referees, the more they prefer confints over p
More information about the R-help
mailing list