【问题标题】:how to get the fstat out of fitlm MATLAB如何从 fitlm MATLAB 中获取 fstat
【发布时间】:2014-06-15 01:32:00
【问题描述】:

我正在使用lm = fitlm(X,y,'linear') 它工作得很好并且输出

lm = 


Linear regression model:
    y ~ 1 + x1 + x2 + x3

Estimated Coefficients:
               Estimate    SE           tStat      pValue    
    (Intercept)      2.1338      0.27403     7.7869    1.6357e-13
    x1              0.07202      0.01757     4.0991    5.5484e-05
    x2             -0.35927      0.12078    -2.9746     0.0032094
    x3             0.020363    0.0041479     4.9092    1.6168e-06


Number of observations: 264, Error degrees of freedom: 260
Root Mean Squared Error: 0.835
R-squared: 0.154,  Adjusted R-Squared 0.144
F-statistic vs. constant model: 15.8, p-value = 1.93e-09

类似的东西。 但是我想获取每个模型的F-statistic 值(在循环中)并导出到文件。我的问题是..我找不到包含F-statisticlm 变量,它是pvaluelm.Steps 也是空的..

================================================ ================================== 还有一个问题,我应该在什么条件下使用这个回归结果?如果x1是我在回归其他组件和残差后想要的组件,我应该说x1在x1的p值小于0.05或模型的p值小于0.05时负责y?

【问题讨论】:

    标签: matlab statistics regression


    【解决方案1】:

    按照fitlm 文档中的建议,您可以在模型上使用anova 函数。然后提取值(这些将用于所有 x 值)并以您喜欢的任何方法保存:

    tbl = anova(lm);
    
    % something like this for just your desired values
    A = [double(tbl.F),double(tbl.pValue)];
    csvwrite('output.csv',A);
    
    % or this dumps the entire result of anova to file
    tbl2 = dataset2table(tbl);
    writetable(tbl2, 'output.csv');
    

    其他变体也可以 - 如果您想使用 X 的多个输入,那么您可以使用 anova 上的 summary 选项并从中提取 F 和 p 值:

    X = cell array of inputs of length n;
    
    F = zeros(n,1);
    p = zeros(n,1);
    
    for m = 1:n;
        lm = fitlm(X{n},y,'linear')
        tbl = anova(lm,'summary');
    
        % you may want to check these indices but should be the right points:
    
        F(n) = double(tbl(2,4));
        p(n) = double(tbl(2,5)); 
    end
    

    【讨论】:

    • F-statistic vs. constant model: 15.8, p-value = 1.93e-09 我想获取这一行的值,而不是每个组件的 p 值。 f 统计量和该模型的 p 值。
    • 对不起,我在问题中使用了大号X
    • 对我的第二个问题,你能给我一些建议吗?
    • 我认为你最好在 CrossValidated 网站上将这部分作为一个单独的问题来询问,因为它与代码方面无关:stats.stackexchange.com
    猜你喜欢
    • 2016-01-18
    • 1970-01-01
    • 2020-10-29
    • 2019-11-25
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    相关资源
    最近更新 更多