You are on page 1of 7

RESTANTA LABORATOR 2 (MATLAB)

Testul "CHI patrat" pentru disperia unei variabile


_
j, o
2
_
ADRESA: Statistics Toolbox / Hypothesis test / ttest
One-sample t-test
Syntax
h =ttest(x)
h = ttest(x,m)
Description
h = ttest(x) performs a t-test of the null hypothesis that data in the vector
x are a random sample from a normal distribution with mean 0 and unknown
variance, against the alternative that the mean is not 0.
The result of the test is returned in h. h = 1 indicates a rejection of the
null hypothesis at the 5% signicance level. h = 0 indicates a failure to reject
the null hypothesis at the 5% signicance level.
h = ttest(x,m) performs a T-test of the hypothesis that the data in x come
from a distribution with mean m. m must be a scalar.
ADRESA: Statistics Toolbox / Hypothesis test / vartest
Chi-square variance test
Syntax
H = vartest(X; V )
Description
H = vartest(X,V) performs a chi-square test of the hypothesis that the data
in the vector X comes from a normal distribution with variance V, against the
alternative that X comes from a normal distribution with a dierent variance.
The result is H = 0 if the null hypothesis (variance is V) cannot be rejected
at the 5% signicance level, or H = 1 if the null hypothesis can be rejected
at the 5% level.
EXEMPLU
x=normrnd(2,3,100,1)
ttest(x,5)
ans = 1
ttest(x,2)
ans = 0
vartest(x,3)
ans = 1
vartest(x,9)
ans = 0

1
LABORATOR 3
REPARTITIA NORMALA 2 DIMENSIONALA (MATLAB)
1. Plotarea densitatii de repartitie N(2,mu,Sigma) ca suprafata in spatiul
tridimensional
2. Generarea a n date N(2,mu,Sigma), independente
3. Plotarea histogramei tridimensionale pt datele generate
4. Estimarea parametrilor mu si Sigma
Generarea suprafetei care da densitatea de repartitie normale 2-
dimensionala
mu = [0 0];
Sigma = [.25 .3; .3 1];
x1 = -3:.2:3; x2 = -3:.2:3;
[X1,X2] = meshgrid(x1,x2);
F = mvnpdf([X1(:) X2(:)],mu,Sigma);
F = reshape(F,length(x2),length(x1));
surf(x1,x2,F);
caxis([min(F(:))-.5*range(F(:)),max(F(:))]);
axis([-3 3 -3 3 0 .4])
xlabel(x1); ylabel(x2); zlabel(Probability Density);
Generarea suprafetei care da densitatea unei mixturi de doua repar-
titii normale 2-dimensionale
mu = [1 1 ; 7 7];
sigma = [4 1.6 ; 1.6 1];
p = [0.3 0.7];
X = gmdistribution(mu, sigma, p);
ezsurf( @(x,y)pdf(X, [x,y]) , [ -6 13], [ -6 13])
2
Generarea a : observatii independente, identic repartizate normal
2-dimensional
Plotarea histogramei
Estimarea parametrilor
mu = [2 9];
Sigma = [.25 .3; .3 1];
X=mvnrnd(mu,Sigma,500);
R = mvnrnd(MU,SIGMA) returns an n-by-d matrix R of random vectors
chosen from the multivariate normal distribution with mean MU, and covariance
SIGMA.
MU is an n-by-d matrix, and mvnrnd generates each row of R using the
corresponding row of mu.
SIGMA is a d-by-d symmetric positive semi-denite matrix, or a d-by-d-
by-n array. If SIGMA is an array, mvnrnd generates each row of R using the
corresponding page of SIGMA, i.e., mvnrnd computes R(i,:) using MU(i,:) and
SIGMA(:,:,i). If the covariance matrix is diagonal, containing variances along
the diagonal and zero covariances on the diagonal, SIGMA may also be specied
as a 1-by-d vector or a 1-by-d-by-n array, containing just the diagonal. If MU is
a 1-by-d vector, mvnrnd replicates it to match the trailing dimension of SIGMA.
hist3(X,[12,12])
obj=gmdistribution.t(X, 1);
obj.mu
obj.Sigma
gmdistribution.t(X; 1)
Description
obj = gmdistribution..t(X,1) constructs an object obj of the @gmdistribution
class containing maximum likelihood estimates of the parameters in a Gaussian
model for data in the n-vector X, where n is the number of observations
Comentariu privind rularea in MATLAB
- Se intra in ecranul de lucru (command window)
- Se trece la "current folder" directorul unde exista sierul tc:t.:
- Se apeleaza scriind direct numele tc:t
- de-comentarea: se marcheaza / ctrl t
- comentarea: se marcheaza / ctrl r
3
GENERAREA DE OBSERVATII INDEPENDENTE, IDENTIC
REPARTIZATE (d; j, ) IN
Fie 1
d
, matrice de ordin d, simetrica si pozitiv denita. Atunci
X = (A
1
, ..., A
d
)
0
~ (d; , ) ==
) (x; , ) =
1
(2)
d=2
(det )
1=2
exp
_

1
2
(x )
0

1
(x )
_
, x =(r
1
, ..., r
d
)
0
1
d
Repartitii marginale, repartitii conditionate
Fie X = (A
1
, ..., A
d
)
0
~ (d; , ) . Consideram partitia
X =
_
_
X
(1)
_
0
,
_
X
(2)
_
0
_
0
, cn X
(1)
= (A
1
, ..., A
r
)
0
, X
(2)
= (A
r+1
, ..., A
d
)
0
=
_
_

(1)
_
0
,
_

(2)
_
0
_
0
, cn
(1)
= (j
1
, ..., j
r
)
0
,
(2)
=
_
j
r+1
, ..., j
d
_
0
=
_

11

12

21

22
_
Repartitiile marginale sunt normale (multidimensionale),
X
(1)
~
_
r;
(1)
,
11
_
X
(2)
~
_
d r;
(2)
,
22
_
Repartitiile conditionate sunt normale (multidimensionale),
X
(1)
[ X
(2)
= x
(2)
~
_
r; '
_
X
(1)
[ X
(2)
= x
(2)
_
, Co
_
X
(1)
, X
(1)
[ X
(2)
= x
(2)
__
'
_
X
(1)
[ X
(2)
= x
(2)
_
=
(1)
+
12

1
22
_
x
(2)

(2)
_
Co
_
X
(1)
, X
(1)
[ X
(2)
= x
(2)
_
=
11

12

1
22

21
notat
=
112
X
(2)
[ X
(1)
= x
(1)
~
_
d r; '
_
X
(2)
[ X
(1)
= x
(1)
_
, Co
_
X
(2)
, X
(2)
[ X
(1)
= x
(1)
__
'
_
X
(2)
[ X
(1)
= x
(1)
_
=
(2)
+
21

1
11
_
x
(1)

(1)
_
Co
_
X
(2)
, X
(2)
[ X
(1)
= x
(1)
_
=
22

21

1
11

12
notat
=
221
4
CAZUL d = 2
Dorim s a gener am valori ale unui vector X,
X = (A
1
, A
2
)
0
~ (2; , )
=(j
1
, j
2
)
0
=
_
o
2
1
j o
1
o
2
j o
1
o
2
o
2
2
_
Utiliz am propriet atile de mai sus:
A
1
~
_
j
1
, o
2
1
_
A
2
[ A
1
= r
1
~ (1 (A
2
[ A
1
= r
1
) , \ (A
1
[ A = r
1
))
1 (A
2
[ A
1
= r
1
) = j
2
+j
o
2
o
1
(r
1
j
1
)
\ (A
2
[ A
1
= r
1
) = o
2
2
_
1 j
2
_
Algoritm de generare:
se genereaz a r
1
ca valoare a unei repartitii
_
j
1
, o
2
1
_
;
se genereaz a r
2
ca valoare a unei repartitii

_
j
2
+j
o
2
o
1
(r
1
j
1
) , o
2
2
_
1 j
2
_
_
;
repet a de : ori;
output (r
11
, r
12
) , ..., (r
n1
, r
n2
)
5
CAZUL d = 3
Dorim s a gener am valori ale unui vector X,
X
(1)
= (A
1
, A
2
)
0
~
_
2;
(1)
,
11
_
X = (A
1
, A
2
, A
3
)
0
~ (3; , )
=(j
1
, j
2
, j
3
)
0
=
_
_
o
2
1
o
12
o
13
o
12
o
2
2
o
23
o
13
o
23
o
2
3
_
_
Utiliz am propriet atile de mai sus:
X = (A
1
, A
2
)
0
~ X
(1)
= (A
1
, A
2
)
0
~
_
2;
(1)
,
11
_
=
_
2; (j
1
, j
2
)
0
,
_
o
2
1
o
12
o
12
o
2
2
__
A
3
[ A
1
= r
1
, A
2
= r
2
~ (1 (A
3
[ (r
1
, r
2
)) , \ (A
3
[ (r
1
, r
2
)))
1 (A
3
[ (r
1
, r
2
))
= j
3
+
_
o
13
o
23
_

_
o
2
1
o
12
o
12
o
2
2
_
1

_
r
1
j
1
r
2
j
2
_
=
= j
3
+
_
o
13
o
23
_
_
_


2
2

2
12

2
1

2
2
12

2
12

2
1

2
2
12

2
12

2
1

2
2


2
1

2
12

2
1

2
2
_
_
_
r
1
j
1
r
2
j
2
_
=
= j
3
+
1
o
2
12
o
2
1
o
2
2
__
o
12
o
23
o
2
2
o
13
_
(r
1
j
1
) +
_
o
12
o
13
o
2
1
o
23
_
(r
2
j
2
)
_
\ (A
3
[ (r
1
, r
2
)) = o
2
3

_
o
13
o
23
_

_
o
2
1
o
12
o
12
o
2
2
_
1

_
o
13
o
23
_
=
= o
2
3

_
o
13
o
23
_
_
_


2
2

2
12

2
1

2
2
12

2
12

2
1

2
2
12

2
12

2
1

2
2


2
1

2
12

2
1

2
2
_
_
_
o
13
o
23
_
=
o
2
3
+
1
o
2
12
o
2
1
o
2
2
_
o
2
1
o
2
23
+o
2
2
o
2
13
2o
12
o
13
o
23
_
6
Algoritm de generare:
se genereaz a (r
1
, r
2
) ca valoare a unei repartitii normale bidimensionale
se genereaz a r
3
ca valoare a unei repartitii normale unidimensionale, con-
ditionate de (r
1
, r
2
)
repet a de : ori;
output (r
11
, r
12
, r
13
) , ..., (r
n1
, r
n2
, r
n3
)
7

You might also like