I have the following code that automatically performs lm between my independent variable (Kpl) and all my other dependent variables (Y1, Y2, ...., Yi):
linear_summary <- lapply(testdata[,-1], function(x) summary(lm(Kpl ~ x)))
The output for this is
Call:
lm(formula = Kpl ~ x)
Residuals:
Min 1Q Median 3Q Max
-1.37567 -0.52392 0.04236 0.67444 0.81316
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.7282 0.3456 5.001 0.000402 ***
x -0.1550 0.2712 -0.571 0.579196
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.772 on 11 degrees of freedom
Multiple R-squared: 0.02883, Adjusted R-squared: -0.05946
F-statistic: 0.3265 on 1 and 11 DF, p-value: 0.5792
$Y2
Call:
lm(formula = Kpl ~ x)
Residuals:
Min 1Q Median 3Q Max
-1.2472 -0.4236 -0.2057 0.7140 1.0348
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.6900 0.9010 0.766 0.460
x 0.8832 0.8767 1.007 0.335
Residual standard error: 0.7495 on 11 degrees of freedom
Multiple R-squared: 0.08447, Adjusted R-squared: 0.001238
F-statistic: 1.015 on 1 and 11 DF, p-value: 0.3354
Etc. (I have truncated it for just the first 2 correlations)
I wanted to extract the final p-value for the whole model for each of the instances (0.5792 and 0.3354 in these two cases). Ideally this would come in some sort of table form with the associated correlation variable, i.e. Y1=0.5792 Y2=0.3354.
Most of the info I can find either seem to only work for a single correlation (as opposed to an sapply with multiple correlations) or I do not seem to get it to work, which could be a problem with my original code.
Any suggestions for a person just starting with R on how to solve this?
Edit: The data looks something like this
| X | Y1 | Y2 | Y3 | Y4 |
| -------- | ------------|-------------|-------------|-------------|
| 0.33767 | 2.33063062 | 1.013212308 | 1.277996888 | 1.373238355 |
| 0.33767 | 0.095967324 | 0.508830529 | 0.789257027 | 0.815877121 |
| 1.010474 | 2.344657045 | 0.842490752 | 1.240582283 | 1.262360905 |
| 1.010474 | 0.08135992 | 0.912535398 | 0.384427466 | 0.409817599 |
| 1.183276 | 0.135626937 | 0.967877981 | 0.505801442 | 0.576288093 |
| 1.536974 | 1.507146148 | 1.428839993 | 1.316569449 | 1.392022619 |
| 1.536974 | 1.255210981 | 1.191822955 | 1.395769591 | 1.41903939 |
| 2.017965 | 1.410299711 | 1.121560244 | 1.369835675 | 1.385143026 |
| 2.017965 | 1.032587109 | 1.372235121 | 1.390878783 | 1.42741762 |
| 2.3436 | 1.275999998 | 0.930400789 | 1.19877482 | 1.217540034 |
| 2.3436 | 1.250513383 | 1.063880146 | 1.206719195 | 1.23325973 |
| 2.387598 | 0.182866909 | 0.89588293 | 0.416923749 | 0.45364797 |
| 2.387598 | 0.097133916 | 0.750430855 | 0.506463633 | 0.03434754 |
These are the actual values that I used to get the correlations above