Home > database >  Pr column missing from coefficients if summary is not called first
Pr column missing from coefficients if summary is not called first

Time:10-15

The following prints two result sets

fit.all <-lm(target ~ .,train )
summary(fit.all) # If I comment out this line then coefs does not include P value
coef(summary(fit.all)) -> coefs 
print(coefs)

However if I comment out the first call to print then the second result set does not include Pr
Why?

[Update]

I can no longer get the p values at all. working on reproducing.

[Update]

I can get at the values this way but I am unsure how to access the Pr column

coef(summary(fit.all)) -> fit.all.summary.coef 
str(fit.all.summary.coef) 
class(fit.all.summary.coef)

output

CodePudding user response:

You haven't provided a dataset to work with, but I suspect it is because of the way you have coded your script. Here is an example with R's iris dataset. Instead of doing it the way you used, I just saved the summary of the model as an object and pulled the coefficients directly from there:

#### Fit Model ####
fit <- lm(Sepal.Length ~ Sepal.Width,
          data = iris)

#### Save Summary as Object ####
sum.fit <- summary(fit)

#### Print Directly ####
sum.fit$coefficients
print(sum.fit$coefficients) # same thing if you want it

This pulls the coefficients and p values directly from the saved summary, which is what I suspect you needed:

              Estimate Std. Error   t value     Pr(>|t|)
(Intercept)  6.5262226  0.4788963 13.627631 6.469702e-28
Sepal.Width -0.2233611  0.1550809 -1.440287 1.518983e-01

Note that running coef(fit) only gives you the coefficients and none of the other estimates:

(Intercept) Sepal.Width 
  6.5262226  -0.2233611 

CodePudding user response:

I was able to access the PR column this way I wonder if it had to do with the PR values being extremely small < 2e^{-16}

fit.all <-lm(target ~ .,train )
coef(summary(fit.all)) -> fit.all.summary.coef
colnames<-colnames(train) 
n= length(colnames)  
cat(" n is ",n,"\n")
tvals <-fit.all.summary.coef[,3]
pvals <-fit.all.summary.coef[,4]
pval <- rep(0,n)
for ( i in 1:n)
{
   cat(colnames[i],tvals[i],pvals[i],"\n")
}
  • Related