Reputation: 11
I am trying to extract p-values from a large list of lm which I created by:
S_models <- dlply(S, "BayStation", function(df)
lm(Temp ~ Date, data = df))
This leaves me with 24 lists of lm for each group (BayStation). I was able to extract the intersect and slope using:
coef<-ldply(S_models, coef)
However, I cannot seem to figure out how to get a list or dataframe of p-values from this large list without doing it individually or manually.
Upvotes: 1
Views: 1285
Reputation: 76432
The following uses base R only and gets the p-values with the function pf
. The quantile and the degrees of freedom are in the list returned by summary
.
sapply(S_models, function(x){
ff <- summary(x)$fstatistic
pf(ff[1], df1 = ff[2], df2 = ff[3], lower.tail = FALSE)
})
Upvotes: 0
Reputation: 887158
We can use map
library(purrr)
result <- map(S_models, ~ summary(.x)$coefficients[,4])
Upvotes: 0
Reputation: 388982
Try using sapply
/lapply
:
result <- sapply(S_models, function(x) summary(x)$coefficients[,4])
#With `lapply`
#result <- lapply(S_models, function(x) summary(x)$coefficients[,4])
Upvotes: 1