Computer Programming II -9Dr. Engin YILDIZTEPE Dr.Alper VAHAPLAR

Exercise • Write a program to standardize (min-max, z-score) numbers entered in the Memo1. Write standardized values into the Memo2.

2 E.Yıldıztepe

1

Standardize - Exercise procedure TForm1. ComboBox1Change (Sender: TObject); var sayi: array of double; i,n:integer; enkucuk, enbuyuk, ortalama, stdsapma:real; Begin if Memo1.Lines.Count>o then begin n:=Memo1.Lines.Count; SetLength(sayi,n); for i:=0 to n-1 do begin sayi[i]:=StrtoFloat(Memo1.Lines[i]); end; enkucuk:=MinValue(sayi); enbuyuk:=MaxValue(sayi); ortalama:=Mean(sayi); stdsapma:=StdDev(sayi);

3 E.Yıldıztepe

Standardize - Exercise … Memo2.Clear; Case ComboBox1.ItemIndex of 0: begin

for i:=0 to n-1 do begin

Memo2.Lines.Add(FormatFloat('0.####0',(sayi[i]-enkucuk)/(enbuyuk-enkucuk)))

end; end; 1: begin for i:=0 to n-1 do begin Memo2.Lines.Add(FormatFloat('0.####0',(sayi[i]-ortalama)/stdsapma));

end;

end; end; //Case’in end end; //procedure end

4 E.Yıldıztepe

2

MomentSkewKurtosis procedure • MomentSkewKurtosis procedure computes the first moment about the origin (zero) and second,third, fourth moments about the mean. • The n. moment about the origin:

• The n. moment about the mean :

5 E.Yıldıztepe

MomentSkewKurtosis procedure • Skewness, the third standardized moment, defined as where μ3 is the third moment about the mean and σ is the standard deviation • Kurtosis, the fourth standardized moment is defined as

where μ4 is the fourth moment about the mean and σ is the standard deviation. 6 E.Yıldıztepe

3

MomentSkewKurtosis procedure • Use of Procedure:

MomentSkewKurtosis(const Data: array of Double; var M1, M2, M3, M4, Skew, Kurtosis: Extended); • • • • • •

M1: 1st moment about the origin. (mean) M2: 2nd moment about the mean. (Variance) M3: 3rd moment about the mean. M4: 4th moment about the mean. Skew: coefficient of Skewness. Kurtosis: coefficient of kurtosis.

• The type of the Array must be double. • The type of the return parameters must be Extended. 7 E.Yıldıztepe

MomentSkewKurtosis procedure – Exercise • Write a program to compute the moments. Display the results with only 3 decimal digits.

8 E.Yıldıztepe

4

MomentSkewKurtosis procedure – Exercise procedure TForm1.RadioButton1Click(Sender: TObject); var sayi: array of double; i,n:integer; m1,m2,m3,m4,sw,kt:extended; Begin n:=Memo1.Lines.Count; SetLength(sayi,n); for i:=0 to n-1 do begin sayi[i]:=StrtoFloat(Memo1.Lines[i]); end; MomentSkewKurtosis(sayi,m1,m2,m3,m4,sw,kt); ……… 9 E.Yıldıztepe

MomentSkewKurtosis procedure – Exercise ……….. if RadioButton1.Checked then Memo2.Lines.Add('1.Moment:'+FormatFloat('#0.##0',m1)) else if RadioButton2.Checked then Memo2.Lines.Add('2.Moment: '+FormatFloat('#0.##0',m2)); else if RadioButton3.Checked then Memo2.Lines.Add('3.Moment: '+FormatFloat('#0.##0',m3)); else if RadioButton4.Checked then Memo2.Lines.Add('4.Moment: '+FormatFloat('#0.##0',m4)); else if RadioButton5.Checked then Memo2.Lines.Add('Çarpıklık: '+FormatFloat('#0.##0',sw)); else if RadioButton6.Checked then Memo2.Lines.Add('Basıklık: '+FormatFloat('#0.##0',kt)); end; 10 E.Yıldıztepe

5

Exercise – Confidence Interval • Write a program to compute the t-confidence interval:

11

E.Yıldıztepe

Exercise – Confidence Interval • Confidence level will be choosen from combobox1 (items:95, 99), degrees of freedom is (n-1), user will enter t-table value, program doesn’t begin unless this value.

12

E.Yıldıztepe

6

Exercise – Confidence Interval procedure TForm1.Button1Click(Sender: TObject); var i,n:integer; dizi:array of double; ort,ssapma,altsinir,ustsinir,ttablo:real; a,u:string; begin if Memo1.Lines.Count>0 then begin if Edit2.Text'' then begin Memo2.Clear; n:=Memo1.Lines.Count; SetLength(dizi,n); for i:=0 to n-1 do begin dizi[i]:=StrtoFloat(Memo1.Lines[i]); end; ort:=Mean(dizi); ssapma:=StdDev(dizi); ttablo:=StrtoFloat(Edit2.Text); altsinir:=ort-(ttablo*(ssapma/(Sqrt(n)))); ustsinir:=ort+(ttablo*(ssapma/(Sqrt(n)))); a:=Formatfloat('0.##0',altsinir); u:=Formatfloat('0.##0',ustsinir); Memo2.Lines.Add('%'+ComboBox1.Text+' Güven aralığı:'); Memo2.Lines.Add(a+'