Basit Lineer Regresyon Programı - Anova :)

Merhaba arkadaşlar birkaç gün önce yazdığım istatistikle ilgili regresyon programımı sizinle paylaşıyorum.
aslında amaçlarım arasında güven aralığı  oluşturmak da vardı. Ama Zaman sıkıntısından dolayı Bu kadarıyla idare edecez artık...
Ekran resimleri aşağıda

Buradan programı İndirebilirsiniz
pearson korelasyonunu bulan versiyonu :)


Kodlarımız aşağıda










unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinBlueprint,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, cxPCdxBarPopupMenu, cxPC;

type
  TForm1 = class(TForm)
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    X: TLabel;
    Y: TLabel;
    Memo1: TMemo;
    Memo2: TMemo;
    Hesapla: TButton;
    Memo3: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    sdr: TLabel;
    sde: TLabel;
    sdt: TLabel;
    ssr: TLabel;
    msr: TLabel;
    sse: TLabel;
    mse: TLabel;
    sst: TLabel;
    fdeger: TLabel;
    cxTabSheet3: TcxTabSheet;
    ysapkalar: TMemo;
    Label18: TLabel;
    eler: TMemo;
    Label19: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Button1: TButton;
    procedure HesaplaClick(Sender: TObject);
    procedure hesaplama;
    procedure anovaolustur;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  toplax,toplaxkare,toplay,toplaykare,toplaxy,alfa1,xeksixortalamakaresi,alfasifir:extended;
  sse1,ssr1,msr1,mse1,sst1:extended;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Clear;
memo2.Lines.Clear;
memo3.Lines.Clear;
eler.Lines.Clear;
ysapkalar.Lines.Clear;

end;

procedure TForm1.HesaplaClick(Sender: TObject);
var
  i,j,k,z: Integer;

begin

if memo1.Lines.Count<>0 then
                       begin

if memo1.Lines.Count=memo2.Lines.Count then
begin

memo3.Lines.Clear;
toplax:=0;
toplaxkare:=0;
toplay:=0;
toplaykare:=0;
toplaxy:=0;
 xeksixortalamakaresi:=0;

for i := 0 to memo1.Lines.Count - 1 do
begin
  toplax:=toplax+StrToFloat(memo1.Lines[i]);
  toplaxkare:=toplaxkare+Sqr(StrToFloat(memo1.Lines[i]));
end;
 for j := 0 to memo2.Lines.Count - 1 do
begin
  toplay:=toplay+StrToFloat(memo2.Lines[j]);
  toplaykare:=toplaykare+Sqr(StrToFloat(memo2.Lines[j]));
end;
  for k := 0 to memo2.Lines.Count - 1 do
begin
  toplaxy:=toplaxy+StrToFloat(memo2.Lines[k])*StrToFloat(memo1.Lines[k]);
 end;


   for z := 0 to memo2.Lines.Count - 1 do
begin
  xeksixortalamakaresi:=xeksixortalamakaresi+sqr(StrToFloat(memo1.Lines[z])-(toplax/memo2.Lines.Count));
 end;





alfa1:=(toplaxy-memo2.Lines.Count*(toplax/memo1.Lines.Count)*(toplay/memo2.Lines.Count))/   (xeksixortalamakaresi ) ;
alfasifir:=(toplay/memo1.Lines.Count)-alfa1*(toplax/memo1.Lines.Count );





memo3.Lines.add('Σxi='+floattostr(toplax)) ;
memo3.Lines.add('Σxi²='+floattostr(toplaxkare));
memo3.Lines.add('Σyi='+floattostr(toplay)) ;
memo3.Lines.add('Σyi²='+floattostr(toplaykare));
memo3.Lines.add('Σxiyi='+floattostr(toplaxy));
memo3.Lines.add('alfa1='+floattostr(alfa1));
memo3.Lines.add('alfa0='+floattostr(alfasifir));
memo3.Lines.add('kestirim='+floattostr(alfasifir)+'+'+floattostr(alfa1)+'*xi');
label1.Caption:='Kestirim Denklemi : '+floattostr(alfasifir)+'+'+floattostr(alfa1)+'*xi';
hesaplama;
end
else
showmessage('xi ler ve yi lerin sayısı eşit değil lütfen kontrol ediniz');

                       end
                       else
                       showmessage('Öncelikle verileri satır satır giriniz');
end;




procedure tform1.hesaplama;
var
p:integer;
begin
ysapkalar.Lines.Clear;
eler.Lines.Clear;

for p := 0 to memo1.lines.count - 1 do
begin
    ysapkalar.Lines.Add(floattostr( ((strtofloat(memo1.Lines[p])*alfa1)+alfasifir)  ))   ;
    eler.Lines.Add(floattostr( strtofloat(memo2.Lines[p])-strtofloat(ysapkalar.Lines[p])));

end;

anovaolustur;

end;



procedure tform1.anovaolustur;
var

x:integer;
begin
  ///  sse1,ssr1,msr1,mse1,sst1:extended;
   ssr1:=0;
   sse1:=0;

  for x := 0 to memo1.Lines.Count - 1 do
  begin

  ssr1:=sqr(strtofloat(ysapkalar.Lines[x])-(toplay/memo1.Lines.Count))+ssr1  ;
  sse1:=sqr(strtofloat(memo2.Lines[x])-strtofloat(ysapkalar.Lines[x]))+sse1;

  end;




    sst1:=ssr1+sse1;
    ssr.Caption:=floattostr(ssr1);
    sse.caption:=floattostr(sse1);
    sst.Caption:=floattostr(sst1);
    sde.Caption:=floattostr((memo1.Lines.Count)-2);
    sdt.Caption:=floattostr((memo1.Lines.Count)-1);
    mse.Caption:=floattostr(strtofloat(sse.Caption)/strtofloat(sde.Caption));
    msr.Caption:=floattostr(strtofloat(ssr.Caption)/strtofloat(sdr.Caption));
    fdeger.Caption:=floattostr(strtofloat(msr.Caption)/strtofloat(mse.Caption));

end;


end.

Yorumlar