Cap. 5

Exercício 5.1

nsim={10,50,1000};
j=0;
While[(j=j+1)≤Length[nsim],
(*data=RandomVariate[NormalDistribution[0,1],nsim[[j]]];*)
data=RandomVariate[NormalDistribution[0,1],nsim[[j]]];
n=Length[data];
empiricalcdf[x_]=(1/n)×(∑_(i=1)^n)If[data[[i]]≤x,1,0];
Print[Plot[{empiricalcdf[x],CDF[NormalDistribution[0,1],x]},{x,-4,4}]]]

(* The empirical c.d.f. is a consistent estimate(tor) of the true c.d.f.! *)

Exercício 5.2

t={0.41,0.58,0.75,0.83,1,1.08,1.17,1.25,1.35};
n=Length[t];
TableForm[Table[{i,
t[[i]],
If[i<n,t[[i+1]]-t[[i]],Null],
If[i<n,(1/((n+0.25)×(t[[i+1]]-t[[i]]))),Null],
((n-i+0.625)/((n+0.25))),
If[i<n,(1/((n-i+0.625)×(t[[i+1]]-t[[i]]))),Null]},{i,1,n}],
TableHeadings->{None,{"i","(Subscript[t, (i)])","(Subscript[t, (i + 1)])-(Subscript[t, (i)])","(OverHat[f])[(Subscript[t, (i)])]","(OverHat[R])[(Subscript[t, (i)])]","(OverHat[λ])[(Subscript[t, (i)])]"}}]
ListPlot[Table[(1/((n-i+0.625)×(t[[i+1]]-t[[i]]))),{i,1,n-1}],PlotStyle->PointSize[0.02],AxesLabel->{"(Subscript[t, (i)])","(OverHat[λ])[(Subscript[t, (i)])]"},AxesOrigin->{0.5,0}]

(* The graph suggests an IHR distribution *)

Exercício 5.3

t=Table[i,{i,0,18,3}];
n=50;
nbins=Length[t]-1;
numberfailures={21,10,7,9,2,1};
survivors=Table[If[j==1,n,n-(∑_(i=1)^(j-1))numberfailures[[i]]],{j,1,nbins}];
f=Table[N[((numberfailures[[j]])/(n×(t[[j+1]]-t[[j]]))),5],{j,1,nbins}];
R=Table[N[((survivors[[j]])/n),5],{j,1,nbins}];
λ=Table[N[((numberfailures[[j]])/(survivors[[j]]×(t[[j+1]]-t[[j]]))),5],{j,1,nbins}];
TableForm[Table[{j,
t[[j]],
t[[j+1]],
survivors[[j]],
numberfailures[[j]],
f[[j]],
R[[j]],
λ[[j]]},{j,1,nbins}],
TableHeadings->{None,{"j","(Subscript[t, j])","(Subscript[t, j + 1])","N((Subscript[t, j]))","N((Subscript[t, j]))-N((Subscript[t, j + 1]))","(OverHat[f])((Subscript[t, j]))","(OverHat[R])((Subscript[t, j]))","(OverHat[λ])((Subscript[t, j]))"}}]
ListPlot[Table[f[[j]],{j,1,nbins}],PlotStyle->PointSize[0.02],AxesLabel->{"(Subscript[t, j])","(OverHat[f])((Subscript[t, j]))"}]
ListPlot[Table[R[[j]],{j,1,nbins}],PlotStyle->PointSize[0.02],AxesLabel->{"(Subscript[t, j])","(OverHat[R])((Subscript[t, j]))"}]
ListPlot[Table[λ[[j]],{j,1,nbins}],PlotStyle->PointSize[0.02],AxesLabel->{"(Subscript[t, j])","(OverHat[λ])((Subscript[t, j]))"}]

(* The graph of the h.r.f. suggests an bathtub distribution *)

Exercício 5.4

t=Table[i,{i,0,1000,100}];
n=432;
nbins=Length[t]-1;
numberfailures={121,80,70,63,30,25,21,10,7,5};
survivors=Table[If[j==1,n,n-(∑_(i=1)^(j-1))numberfailures[[i]]],{j,1,nbins}];
f=Table[N[((numberfailures[[j]])/(n×(t[[j+1]]-t[[j]]))),5],{j,1,nbins}];
R=Table[N[((survivors[[j]])/n),5],{j,1,nbins}];
λ=Table[N[((numberfailures[[j]])/(survivors[[j]]×(t[[j+1]]-t[[j]]))),5],{j,1,nbins}];
TableForm[Table[{j,
t[[j]],
t[[j+1]],
survivors[[j]],
numberfailures[[j]],
f[[j]],
R[[j]],
100×λ[[j]]},{j,1,nbins}],
TableHeadings->{None,{"j","(Subscript[t, j])","(Subscript[t, j + 1])","N((Subscript[t, j]))","N((Subscript[t, j]))-N((Subscript[t, j + 1]))","(OverHat[f])((Subscript[t, j]))","(OverHat[R])((Subscript[t, j]))","(10^2)×(OverHat[λ])((Subscript[t, j]))"}}]

Exercício 5.6: Exponential(1) is CHR -> TTT plot should resemble a straight line

i=1;
n=1000;
t=Sort[RandomVariate[ExponentialDistribution[1],n]];
t[[0]]=0;
ListLinePlot[Prepend[Table[{i/n,(((∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],{0,0}],AspectRatio->1]

Exercício 5.6': Gamma(0.2,1) is DHR -> TTT plot should resemble a convex line

i=1;
n=1000;
t=Sort[RandomVariate[GammaDistribution[0.2,1],n]];
t[[0]]=0;
ListLinePlot[Prepend[Table[{i/n,(((∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],{0,0}], AspectRatio->1]

Exercício 5.6'': Gamma(2.5,1) — IHR -> TTT plot should resemble a concave line

i=1;
n=1000;
t=Sort[RandomVariate[GammaDistribution[2.5,1],n]];
t[[0]]=0;
ListLinePlot[Prepend[Table[{i/n,(((∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],{0,0}],AspectRatio->1]

Exercício 5.7

t={0.41,0.58,0.75,0.83,1,1.08,1.17,1.25,1.35};
n=Length[t];
t[[0]]=0;
TableForm[Table[{i,
t[[i]],
t[[i]]-t[[i-1]],
n-i+1,
(n-i+1)×(t[[i]]-t[[i-1]]),
(∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]),
(((∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],
TableHeadings->{None,{"i","(Subscript[t, (i)])","(Subscript[t, (i)])-(Subscript[t, (i - 1)])","n-i+1","(n-i+1)×[(Subscript[t, (i)])-(Subscript[t, (i - 1)])]","τ[(Subscript[t, (i)])]","((τ[(Subscript[t, (i)])])/(τ[(Subscript[t, (n)])]))"}}]
ListLinePlot[Prepend[Table[{i/n,(((∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],{0,0}],AspectRatio->1]

(* TTT plot resembles a concave line, thus, suggesting a IHR model *)

Exercício 5.9 (* Data from Exercise 5.10 *)

t={0.30,0.55,0.56,0.86,0.93,1.15,1.42,1.75};
n=Length[t];
t[[0]]=0;
TableForm[Table[{i,
t[[i]],
t[[i]]-t[[i-1]],
n-i+1,
(n-i+1)×(t[[i]]-t[[i-1]]),
(∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]),
(((∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],
TableHeadings->{None,{"i","(Subscript[t, (i)])","(Subscript[t, (i)])-(Subscript[t, (i - 1)])","n-i+1","(n-i+1)×[(Subscript[t, (i)])-(Subscript[t, (i - 1)])]","τ[(Subscript[t, (i)])]","((τ[(Subscript[t, (i)])])/(τ[(Subscript[t, (n)])]))"}}]
ListLinePlot[Prepend[Table[{i/n,(((∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],{0,0}],AspectRatio->1]

(* TTT plot is close to a concave line, thus, suggesting a IHR model *)

Exercício 5.9 (* Data from Exercise 5.12 *)

t={49,73,103,140,162,164,181,196,232,248,288,290,309,377,388,464,500}; n=Length[t];
t[[0]]=0;
TableForm[Table[{i,
t[[i]],
t[[i]]-t[[i-1]],
n-i+1,
(n-i+1)×(t[[i]]-t[[i-1]]),
(∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]),
(((∑_(j=1)^i)(n-j+1.)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],
TableHeadings->{None,{"i","(Subscript[t, (i)])","(Subscript[t, (i)])-(Subscript[t, (i - 1)])","n-i+1","(n-i+1)×[(Subscript[t, (i)])-(Subscript[t, (i - 1)])]","τ[(Subscript[t, (i)])]","((τ[(Subscript[t, (i)])])/(τ[(Subscript[t, (n)])]))"}}]
ListLinePlot[Prepend[Table[{i/n,(((∑_(j=1)^i)(n-j+1)×(t[[j]]-t[[j-1]]))/((∑_(j=1)^n)(n-j+1)×(t[[j]]-t[[j-1]])))},{i,1,n}],{0,0}],AspectRatio->1]

(* TTT plot is close to a concave line, thus, suggesting a IHR model *)

Exercício 5.10

data={0.30,0.55,0.56,0.86,0.93,1.15,1.42,1.75};
sorteddata=Sort[data];
n=Length[sorteddata];

abcordExpProbPlot=Table[{Log[(n+1)/(n-i+1)],sorteddata[[i]]},{i,1,n}];
ListPlot[abcordExpProbPlot,AspectRatio->1]

(((((sorteddata[[n]]-sorteddata[[1]])/(Log[(n+1)/(n-n+1)]-Log[(n+1)/(n-1+1)]))))^(-1))

data={0.30,0.55,0.56,0.86,0.93,1.15,1.42,1.75};
sorteddata=Sort[data];
n=Length[sorteddata];

abcordExpProbPlot=Table[{Log[(n+0.25)/(n-i+0.625)],sorteddata[[i]]},{i,1,n}];
ListPlot[abcordExpProbPlot,AspectRatio->1]

(((((sorteddata[[n]]-sorteddata[[1]])/(Log[(n+0.25)/(n-n+0.625)]-Log[(n+0.25)/(n-1+0.625)]))))^(-1))

Exercício 5.10': exponential probability plot with simulated exponential data

data=RandomVariate[ExponentialDistribution[1.], 1000];
sorteddata=Sort[data];
n=Length[sorteddata];

abcordExp=Table[{Log[(n+1)/(n-i+1)],sorteddata[[i]]},{i,1,n}];
ListPlot[abcordExp, AxesOrigin->{0,0},AspectRatio->1]

(((((sorteddata[[n]]-sorteddata[[1]])/(Log[(n+1)/(n-n+1)]-Log[(n+1)/(n-1+1)]))))^(-1))

(((((sorteddata[[Floor[0.9×n]]]-sorteddata[[Floor[0.1×n]]])/(Log[(n+1)/(n-Floor[0.9×n]+1)]-Log[(n+1)/(n-Floor[0.1×n]+1)]))))^(-1))

(* Unsurprisingly, the probability plot is very close to a straight line! *)
(* The first and last ordered obs. should be not used in the estimation of the scale parameter... *)

Exercício 5.11

data={2.001, 2.007, 2.017, 2.026, 2.036, 2.075, 2.077, 2.082, 2.101, 2.137,2.156, 2.161, 2.181, 2.196, 2.214, 2.227, 2.320, 2.367, 2.424, 2.443,2.444, 2.449, 2.478, 2.520, 2.579, 2.581, 2.598, 2.637, 2.691, 2.715,2.720, 2.825, 2.863, 2.867, 3.016, 3.176, 3.360, 3.413, 3.567, 3.721,3.727, 3.769, 3.803, 4.329, 4.420, 4.795, 6.009, 6.281, 6.784, 8.305};
sorteddata=Sort[data];
n=Length[sorteddata];

abcordParetoProbPlot=Table[{Log[(n+1)/(n-i+1)],Log[sorteddata[[i]]]},{i,1,n}];
ListPlot[abcordParetoProbPlot,AspectRatio->1]

(* The probability plot is approximately linear, thus, the data set seems to have been generated by a Pareto model *)

Exercício 5.12

data={49,73,103,140,162,164,181,196,232,248,288,290,309,377,388,464,500};
sorteddata=Sort[data];
n=Length[sorteddata];

abcordParetoProbPlot=Table[{Log[Log[(n+1)/(n-i+1)]],Log[sorteddata[[i]]]},{i,1,n}];
ListPlot[abcordParetoProbPlot,AspectRatio->1]

(* The probability plot is approximately linear, thus, the data set seems to have been generated by a Weibull model *)

Exercício 5.13

data={1.242,1.626,0.123,2.957,0.388,3.841,1.961,0.938};
sorteddata=Sort[data];
n=Length[sorteddata];

abcordParetoProbPlot=Table[{Log[(n+1)/(n-i+1)],sorteddata[[i]]},{i,1,n}];
ListPlot[abcordParetoProbPlot,AspectRatio->1]

(((((sorteddata[[n]]-sorteddata[[1]])/(Log[(n+1)/(n-n+1)]-Log[(n+1)/(n-1+1)]))))^(-1))

Exercício 5.14

data=Sort[{1.242,1.626,0.123,2.957,0.388,3.841,1.961,0.938}];
n=Length[data];
fde=Table[N[i/n,5],{i,1,n}];
fdeatras=Table[N[(i-1)/n,5],{i,1,n}];
fdconjecturada=Table[1-Exp[-0.56×data[[i]]],{i,1,n}];
fdemenosfdc=fde-fdconjecturada;
fdcmenosfdeatras=fdconjecturada-fdeatras;
values=TableForm[Transpose[{data,fde,fdeatras,fdconjecturada,fdemenosfdc,fdcmenosfdeatras}],TableHeadings->{Automatic,{"(Subscript[t, (i)])","(i/n)","((i - 1)/n)","(Subscript[F, 0])[(Subscript[t, (i)])]","(i/n)-(Subscript[F, 0])[(Subscript[t, (i)])]","(Subscript[F, 0])[(Subscript[t, (i)])]-((i - 1)/n)"}}]
dplus=Max[Max[fdemenosfdc],0]
dminus=Max[Max[fdcmenosfdeatras],0]
Max[dplus,dminus]

Exercício 5.22

a={100,7120,24110,36860,340,12910,28570,38540,940, 13670,31620,42110,5670,19490,32800,43970,6010,23700, 34910, 64730};
r=Dimensions[a][[1]];
N[(1/r)(∑_(i=1)^r)a[[i]],5]
N[(1/r)(∑_(i=1)^r)Log[a[[i]]],5]
N[((2×r)/(1+((r+1)/(6 r))))(Log[(((∑_(i=1)^r)a[[i]])/r)]-(1/r)(∑_(i=1)^r)Log[a[[i]]]),5]

Exercício 5.23

a={21.2,26.7,11.3,2.8,12.6,0.1,2.1,7.5,6.7,2.3,15.3,4.3,14.1,16.9,7.7,5.8,7.3,32.1,17.6,4.5};
r=Dimensions[a][[1]];
N[(1/r)(∑_(i=1)^r)a[[i]],5]
N[(1/r)(∑_(i=1)^r)Log[a[[i]]],5]
N[((2×r)/(1+((r+1)/(6 r))))(Log[(((∑_(i=1)^r)a[[i]])/r)]-(1/r)(∑_(i=1)^r)Log[a[[i]]]),5]

Exercício 5.24

a={6700,4600,4100,14000,850,5400,3100,5000,2600,4700};
r=Dimensions[a][[1]];
N[(1/r)(∑_(i=1)^r)a[[i]],5]
N[(1/r)(∑_(i=1)^r)Log[a[[i]]],5]
N[((2×r)/(1+((r+1)/(6 r))))(Log[(((∑_(i=1)^r)a[[i]])/r)]-(1/r)(∑_(i=1)^r)Log[a[[i]]]),5]

Exercício 5.29

λ=(50./(5613×8760))
λL=(74.22/(2×5613×8760))
λU=(129.6/(2×5613×8760))


Exp[-λ×8760]
(((1-(1./5613)))^50)
Exp[-λU×8760]
Exp[-λL×8760]

-((Log[1-0.8])/λ)
((-((Log[1-0.8])/λ))/(24×365))
-((Log[1-0.8])/(λU))
-((Log[1-0.8])/(λL))

Exercício 5.30

r={8};
ratio={20/8};
Table[N[(((∑_(i=1)^(r[[j]]))(1/(ratio[[k]]×r[[j]]-i+1)))/((∑_(i=1)^(r[[j]]))(1/(r[[j]]-i+1)))),5],{k,1,Dimensions[ratio][[1]]},{j,1,Dimensions[r][[1]]}]

r={10,20,30,50,100};
ratio={1.1,1.2,1.3,1.5,2,3};
MatrixForm[Table[N[ (((∑_(i=1)^(r[[j]]))(1/(ratio[[k]]×r[[j]]-i+1)))/((∑_(i=1)^(r[[j]]))(1/(r[[j]]-i+1)))),5],{k,1,Dimensions[ratio][[1]]},{j,1,Dimensions[r][[1]]}]]

r={10,20,30,50,100};
ratio={1.1,1.2,1.3,1.5,2,3};
MatrixForm[Table[N[(1- (((∑_(i=1)^(r[[j]]))(1/(ratio[[k]]×r[[j]]-i+1)))/((∑_(i=1)^(r[[j]]))(1/(r[[j]]-i+1)))))*100,5],{k,1,Dimensions[ratio][[1]]},{j,1,Dimensions[r][[1]]}]]