简体   繁体   中英

How to extract p-values

I've been trying for a while to regress between the first observation and the rest of the 199 observations of my data set. I used the lapply function and the regression result is stored as a list in the environment. My aim is to get only the list of p_values as a data frame and determine how many observations are less than 0.05. Any help would be appreciated!

## Here are the code I am using right now.
myre1 <- apply(2:ncol(muscle), function(x) lm(muscle[,1] ~ muscle[,x], data = muscle))
myre2 <- lapply(muscle[,-1], function(x) lm(muscle$GIR ~ x))

## To extract the coefficient
myre3 <- lapply(2:ncol(muscle), function(x) coefficients(lm(muscle[,1] ~ muscle[,x], data = muscle)))
myre4 <- lapply(muscle[,-1], function(x) coefficients(lm(muscle$GIR ~ x)))

Try this. You'll get the coefficients along with the p.values

sum1 <- lapply(mre1, function(x) summary(x)$coefficients)
sum2 <- lapply(mre2, function(x) summary(x)$coefficients)

You may have to convert the sum1 and sum2 to data frame.

Edit:

To extract the p values alone

sum1 <- lapply(mre1, function(x) summary(x)$coefficients[10:12])
sum2 <- lapply(mre2, function(x) summary(x)$coefficients[7:8])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM