如何为我的拟合函数计算p值?

时间:2019-06-04 15:36:52

标签: matlab p-value

我已经将3个高斯函数的混合拟合到我的数据中,并且拟合得很好。我的问题是拟合在数字上定义得如何。是否可以通过p值定义。如果是,那我该如何从拟合函数本身进行计算。

   g = fittype( @(c1,c2,p5,p6,p3,p4,p1,p2, x) (c1)*(1/(p6*sqrt(2*pi)))*exp(-((x-p5).^2)./(2*(p6.^2))) + ...
   (c2)*(1/(p4*sqrt(2*pi)))*exp(-((x-p3).^2)./(2*(p4.^2))) + ...
    (1-c1-c2)*(1/(p2*sqrt(2*pi)))*exp(-((x-p1).^2)./(2*(p2.^2)))       );

 %xr and yr is data (basically normalized histogram) 
[fE,GE,O] = fit(xr',yr',g,'StartPoint',startingVals);

%O gives me following quantity. 
        numobs: 50
         numparam: 8
    residuals: [50×1 double]
     Jacobian: [50×8 double]
     exitflag: 3
firstorderopt: 7.763960157882235e-04
   iterations: 24
    funcCount: 225
 cgiterations: 0
    algorithm: 'trust-region-reflective'
     stepsize: 0.002272922321389
      message: 'Success, but fitting stopped because change in residual…'

这里没有p值。如何计算谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用corrcoef功能,请参见matlab documentation

基本上,如果您有数据y和拟合函数Y的预测数据,则只需执行以下操作:

[R,p] = corrcoef(y, Y);

在高斯拟合之后,哪个将为您提供R值,以及数据与预测数据之间的相关性的p值,因此基本上可以证明拟合的效果。

yY必须对应于相同的输入值:

假设f是数据的“功能”。它验证 y = f(x),(对于x的每个值,您都有一个测量值y)。

然后,您必须具有Y = f_fitted(x),其中f_fitted是因您拟合而产生的高斯函数。

相关问题