MKZR:Dodatek
Z Skrypty dla studentów Ekonofizyki UPGOW
(Różnice między wersjami)
(→Histogramy) |
(→Histogramy 1D) |
||
Linia 26: | Linia 26: | ||
bar(XX,NN) | bar(XX,NN) | ||
+ | </source> | ||
+ | |||
+ | <source lang='matlab'> | ||
+ | |||
+ | xmax=5; | ||
+ | xmin=-5; | ||
+ | h=.1; | ||
+ | mydata=normrnd (0,1,10000,1); | ||
+ | [NN,XX]=hist(mydata,[xmin:h:xmax],1/h); | ||
+ | figure(1) | ||
+ | plot(XX,NN,"-",XX,normpdf(XX,0,1),"r-") | ||
+ | figure(2) | ||
+ | bar(XX,NN) | ||
+ | size(NN) | ||
+ | #hist(,[-5:0.1:5],1/0.1) | ||
+ | # by hand | ||
+ | NN=zeros(1,101); | ||
+ | for i=1:length(mydata) | ||
+ | idx= ceil ( (mydata(i)-xmin)/(xmax-xmin) * length(NN) ) ; | ||
+ | if idx>0 && idx<=length(NN) | ||
+ | NN(idx)++; | ||
+ | endif | ||
+ | endfor | ||
+ | |||
+ | |||
+ | figure(3) | ||
+ | plot(XX,NN) | ||
</source> | </source> | ||
Wersja z 07:45, 12 maj 2010
Spis treści |
Histogramy
Ważną umiejętnością jest estymacja funkcji gęstości z pewnej (dużej) licznby danych liczbowych. Proces taki jest nazywany histogramowaniem.
Histogram jest to sposób przedstawienia rozkładu empiczycznego pewnej cechy. W kontekście ciągłej zmiennej losowej przyjmującej można sobie wyobrazić, że dzielimy przestrzeń
Proszę zauważyć ze drugi argument jest normą tego histogramu, która zgodnie z dokumentacja (help hist) jest sumą wartości wszystkich słupków. Ponieważ chcemy porównać ten histogram z gęstością to mamy:
\(1=\int_0^\infty f(x) dx=\sum_{i=1}^N f(x_i) h\)
z czego nam wynika, że suma wysokości słupków gęstości unormowanej do jedynki wynosi:
\(\sum_{i=1}^N f(x_i) =1/h\)
Histogramy 1D
xmax=5; h=.1; mydata=normrnd (0,1,10000,1); [NN,XX]=hist(mydata,[-xmax:h:xmax],1/h); plot(XX,NN,"-",XX,normpdf(XX,0,1),"r-") bar(XX,NN)
xmax=5; xmin=-5; h=.1; mydata=normrnd (0,1,10000,1); [NN,XX]=hist(mydata,[xmin:h:xmax],1/h); figure(1) plot(XX,NN,"-",XX,normpdf(XX,0,1),"r-") figure(2) bar(XX,NN) size(NN) #hist(,[-5:0.1:5],1/0.1) # by hand NN=zeros(1,101); for i=1:length(mydata) idx= ceil ( (mydata(i)-xmin)/(xmax-xmin) * length(NN) ) ; if idx>0 && idx<=length(NN) NN(idx)++; endif endfor figure(3) plot(XX,NN)