Professional Documents
Culture Documents
Nomor 2
Panggil rgamma(200,a,b)
Untuk (a=1,b=2)
Untuk (a=2,b=1)
II. Syntax R
library(MASS)
library(fitdistrplus)
library(actuar)
Nomor 1
mtcars
wt<-mtcars$wt
wt
descdist(wt, boot=1000)
logistic_fit<-fitdist(wt, distr='logis')
gamma_fit<-fitdist(wt, distr='gamma')
log_normal_fit<-fitdist(wt, distr='lnorm')
exponential_fit<-fitdist(wt, distr='exp')
summary(normal_fit)
summary(logistic_fit)
summary(gamma_fit)
summary(log_normal_fit)
summary(exponential_fit)
par(mfrow=c(2,2))
plot.legend<-c("Logistik","Gamma")
gofstat(list(logistic_fit, gamma_fit),
fitnames=c('Logistik','Gamma'))
Nomor 2
data<-c(rgamma(200,1,2),rgamma(200,2,1))
descdist(data, boot=1000)
gamma_fit<-fitdist(data, distr='gamma')
exponential_fit<-fitdist(data, distr='exp')
summary(gamma_fit)
summary(exponential_fit)
par(mfrow=c(2,2))
plot.legend<-c("Logistik","Gamma")
denscomp(list(exponential_fit, gamma_fit),
legendtext=plot.legend)
gofstat(list(exponential_fit, gamma_fit),
fitnames=c('Eksponensial','Gamma'))
III. Keluaran R
> library(MASS)
> library(fitdistrplus)
> library(actuar)
> mtcars
Nomor 1
> #I. Kandidat Model (Klasik)
mpg cyl disp hp drat wt qsec vs am gear c
arb
Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4
4
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4
4
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4
1
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3
1
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3
2
Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3
1
Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3
4
Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4
2
Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4
2
Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4
4
Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4
4
Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3
3
Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3
3
Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3
3
Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3
4
Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3
4
Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3
4
Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4
1
Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4
2
Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4
1
Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3
1
Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3
2
AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3
2
Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3
4
Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3
2
Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4
1
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5
2
Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5
2
Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5
4
Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5
6
Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5
8
Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4
2
> wt<-mtcars$wt
> wt
[1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.4
40 4.070 3.730
[14] 3.780 5.250 5.424 5.345 2.200 1.615 1.835 2.465 3.520 3.435 3.8
40 3.845 1.935
[27] 2.140 1.513 3.170 2.770 3.570 2.780
> plotdist(wt, hist=TRUE, demp=TRUE)
> descdist(wt, boot=1000)
summary statistics
------
min: 1.513 max: 5.424
median: 3.325
mean: 3.21725
estimated sd: 0.9784574
estimated skewness: 0.4659161
estimated kurtosis: 3.416595
>
> summary(logistic_fit)
Fitting of the distribution ' logis ' by maximum likelihood
Parameters :
estimate Std. Error
location 3.1891264 0.16274434
scale 0.5339408 0.07967224
Loglikelihood: -44.02487 AIC: 92.04973 BIC: 94.9812
Correlation matrix:
location scale
location 1.000000000 -0.009056598
scale -0.009056598 1.000000000
> summary(gamma_fit)
Fitting of the distribution ' gamma ' by maximum likelihood
Parameters :
estimate Std. Error
shape 10.847529 2.6712156
rate 3.371673 0.8497715
Loglikelihood: -43.64553 AIC: 91.29106 BIC: 94.22253
Correlation matrix:
shape rate
shape 1.0000000 0.9770604
rate 0.9770604 1.0000000
> summary(log_normal_fit)
Fitting of the distribution ' lnorm ' by maximum likelihood
Parameters :
estimate Std. Error
meanlog 1.1217390 0.05524238
sdlog 0.3124981 0.03906046
Loglikelihood: -44.08066 AIC: 92.16132 BIC: 95.09279
Correlation matrix:
meanlog sdlog
meanlog 1 0
sdlog 0 1
> summary(exponential_fit)
Fitting of the distribution ' exp ' by maximum likelihood
Parameters :
estimate Std. Error
rate 0.3108245 0.05494595
Loglikelihood: -69.39286 AIC: 140.7857 BIC: 142.2515
> #III. Uji Kecocokan (GOF Test)
> par(mfrow=c(2,2))
> plot.legend<-c("Logistik","Gamma")
> denscomp(list(logistic_fit, gamma_fit), legendtext=plot.legend)
> cdfcomp(list(logistic_fit, gamma_fit), legendtext=plot.legend)
> qqcomp(list(logistic_fit, gamma_fit), legendtext=plot.legend)
> ppcomp(list(logistic_fit, gamma_fit), legendtext=plot.legend)
> gofstat(list(logistic_fit, gamma_fit), fitnames=c('Logistik','Gamma'))
Goodness-of-fit statistics
Logistik Gamma
Kolmogorov-Smirnov statistic 0.11313006 0.13786900
Cramer-von Mises statistic 0.06623931 0.09956949
Anderson-Darling statistic 0.48196368 0.57298212
Goodness-of-fit criteria
Logistik Gamma
Akaike's Information Criterion 92.04973 91.29106
Bayesian Information Criterion 94.98120 94.22253
>
Nomor 2
> #I. Kandidat Model (Klasik)
> data<-c(rgamma(200,1,2),rgamma(200,2,1))
> data
[1] 5.175071e-01 4.809100e-01 1.265785e-01 1.541833e-01 2.130469e-
01 1.142279e+00
[7] 3.910837e-01 1.317159e-01 6.278423e-01 1.124120e-01 2.073370e-
01 1.435835e-01
[13] 1.890969e-01 9.949903e-01 1.170575e+00 3.000764e-01 1.400939e+
00 2.777929e-01
[19] 1.452257e-01 1.694074e+00 4.127860e-02 4.006271e-01 2.052033e-
01 5.784890e-01
[25] 4.337144e-01 4.855763e-01 1.375935e-01 1.157096e+00 1.000599e-
01 1.284729e+00
[31] 1.278448e-01 8.596375e-02 8.901525e-02 2.663807e-01 8.923130e-
01 6.950004e-01
[37] 7.516783e-02 1.079641e-01 1.339833e-01 2.119346e-01 1.282611e-
01 4.484140e-02
[43] 1.660661e+00 4.981227e-01 3.099231e+00 3.536924e-01 3.163598e-
01 5.970886e-01
[49] 5.018677e-01 6.852675e-03 3.015142e-01 1.842803e+00 4.341750e-
01 5.194566e-01
[55] 8.636620e-02 1.257334e-01 3.950247e-01 4.603288e-02 2.279208e-
01 1.156046e-01
[61] 8.461582e-01 5.838289e-01 1.409032e+00 1.840810e+00 1.871832e-
01 2.691646e+00
[67] 1.132872e+00 4.024472e-01 1.499024e+00 5.507722e-01 6.476091e-
01 1.908698e+00
[73] 4.458580e-02 8.440544e-01 1.759550e-01 1.688901e-01 1.514485e-
01 1.011451e-01
[79] 2.512702e-01 7.186195e-01 2.113763e-01 9.221025e-05 3.402728e-
01 3.867971e-02
[85] 1.276881e+00 4.363994e-02 5.058100e-01 4.738602e-01 6.366044e-
02 8.430086e-01
[91] 6.716431e-01 4.609554e-01 5.905466e-02 4.708209e-01 3.768012e+
00 7.905274e-01
[97] 3.544065e-01 1.323203e+00 1.953453e+00 7.017232e-02 3.613552e-
02 1.195152e-01
[103] 7.000375e-03 1.408225e-01 2.213492e-01 7.880244e-01 7.979938e-
01 3.308375e-01
[109] 4.251679e-01 1.025944e-01 4.967471e-02 7.630911e-01 4.064254e-
01 6.433618e-01
[115] 4.731613e-02 3.147584e-01 9.615011e-01 2.841276e-01 1.357421e-
01 5.125734e-01
[121] 1.399654e-02 6.974237e-01 1.914415e-01 7.987125e-02 4.953481e-
01 1.845709e-01
[127] 2.199081e-01 6.825624e-01 5.511733e-01 8.919217e-01 4.994499e-
03 7.434318e-01
[133] 1.960880e-02 4.343037e-01 9.936417e-01 2.496596e-01 4.367266e-
01 7.154534e-02
[139] 8.604476e-01 4.804126e-01 3.296449e-01 6.531014e-01 2.356464e+
00 5.240935e-01
[145] 1.835975e-01 1.724804e-01 1.699560e+00 3.237604e+00 6.182117e-
01 3.840545e-01
[151] 4.868306e-01 3.782060e-01 4.791756e-01 9.126818e-01 3.503809e-
01 9.566578e-01
[157] 2.120123e-01 8.472719e-02 5.703061e-01 6.980122e-02 3.057132e-
01 1.194620e-01
[163] 1.081277e+00 7.062278e-01 3.679197e-02 6.275575e-02 2.379663e-
03 7.084118e-02
[169] 7.950605e-01 3.023873e-01 8.752471e-01 8.609003e-01 2.313949e-
01 9.572771e-02
[175] 7.611735e-01 3.926244e-01 4.126693e-01 1.434369e-01 4.360550e-
01 2.488161e-01
[181] 2.986786e-02 3.229794e-02 6.908280e-01 6.453717e-01 5.797743e-
01 1.405581e-01
[187] 2.693559e-02 2.172535e-01 3.323530e-01 1.815207e-01 4.570859e-
01 6.617452e-01
[193] 2.674505e-01 2.839967e-01 5.451555e-01 5.856351e-01 1.744270e-
01 1.489528e+00
[199] 1.522723e+00 3.240284e-01 1.682029e+00 1.839104e+00 9.390940e-
01 1.041523e+00
[205] 9.921425e-01 7.658615e-01 1.042651e+00 7.619662e+00 8.480781e-
01 3.238333e+00
[211] 5.876525e+00 9.074774e-01 7.699497e-01 7.059235e-01 2.166233e+
00 9.906716e-01
[217] 7.830856e-01 5.549779e-01 1.860854e+00 1.857860e+00 4.917564e-
01 1.069685e+00
[223] 2.393805e+00 4.729557e-01 1.302785e+00 3.886782e+00 1.110057e+
00 9.864669e+00
[229] 1.909528e+00 1.889407e+00 4.291006e+00 5.531164e-01 5.596616e-
01 1.693863e+00
[235] 1.227512e+00 3.917994e+00 3.759192e+00 1.251343e+00 1.230044e+
00 1.275482e+00
[241] 7.187333e-01 3.012163e+00 9.918603e-01 8.151378e-01 2.485948e+
00 3.350309e+00
[247] 3.086507e-01 1.119883e-01 1.898790e+00 2.213352e+00 6.168110e-
01 2.468423e+00
[253] 1.724436e+00 4.670868e+00 1.802699e+00 4.021791e+00 5.049150e-
01 1.881827e+00
[259] 9.234612e-01 3.467148e+00 6.463375e+00 3.585417e-01 1.296505e+
00 2.103961e+00
[265] 1.422001e+00 3.352897e+00 6.380301e-01 3.787635e+00 1.009738e+
00 1.937477e+00
[271] 1.826191e+00 1.222460e+00 1.001389e+00 1.094402e+00 1.341398e+
00 2.336899e+00
[277] 3.308987e+00 3.045693e+00 1.649172e+00 3.427740e+00 5.944086e-
01 3.065267e+00
[283] 1.158719e+00 6.645397e-01 2.731783e+00 2.431830e+00 3.955370e+
00 3.389534e+00
[289] 1.552137e+00 1.202692e+00 2.046955e+00 1.80 5194e+00 3.608584e-
01 1.517270e+00
[295] 1.872516e+00 1.116488e+00 1.264134e+00 7.890828e-01 1.983175e+
00 3.886358e+00
[301] 1.282560e+00 4.136352e-01 4.765856e+00 1.387027e+00 2.028862e+
00 1.174118e+00
[307] 2.334367e+00 1.412138e+00 1.345064e+00 5.371530 e+00 1.607779e+
00 1.798135e+00
[313] 8.558757e-01 2.609905e+00 4.444806e+00 9.072516e-01 3.526173e+
00 1.628419e+00
[319] 1.994287e+00 2.234088e+00 4.490957e+00 2.207536e+00 1.658167e+
00 7.265782e-01
[325] 1.277269e+00 7.726965e-01 1.718936e+00 2.478502e+00 1.071988e+
00 1.162460e+00
[331] 1.197958e+00 3.606731e+00 1.338562e+00 7.149872e-01 3.509390e+
00 9.455549e-01
[337] 1.880696e+00 1.878820e+00 2.347105e-01 2.264610e+00 2.024909e+
00 5.598625e-01
[343] 2.481266e+00 3.752639e-01 1.516338e+00 2.212168e+00 2.634479e+
00 2.214708e+00
[349] 6.748269e-01 1.412463e+00 1.045626e+00 4.600704e-01 2.257692e+
00 7.318487e-01
[355] 2.010217e+00 7.059401e+00 1.120078e+00 1.118478e+00 3.708588e+
00 2.885959e+00
[361] 1.549433e+00 1.060447e+00 4.540664e-01 1.531884e+00 8.712563e+
00 6.426063e-01
[367] 1.223818e+00 8.508269e-01 1.290549e+00 1.646958e+00 1.872409e+
00 2.068128e+00
[373] 1.228377e+00 5.083696e+00 9.273767e-01 2.612578e+00 1.601408e+
00 7.321001e-01
[379] 1.611237e+00 3.310069e+00 3.085399e+00 1.088623e+00 3.347928e+
00 2.434346e+00
[385] 1.800685e+00 2.097528e+00 1.315683e+00 5.490137e+00 1.970181e+
00 3.125599e+00
[391] 9.737240e-01 5.297732e-01 9.881235e-01 4.049106e+00 3.796296e-
01 2.258658e+00
[397] 2.598038e+00 1.453450e+00 2.904453e+00 1.676894e+00
> plotdist(data, hist=TRUE, demp=TRUE)
>
> summary(exponential_fit)
Fitting of the distribution ' exp ' by maximum likelihood
Parameters :
estimate Std. Error
rate 0.7916638 0.03958313
Loglikelihood: -493.4474 AIC: 988.8947 BIC: 992.8862
Goodness-of-fit criteria
Eksponensial Gamma
Akaike's Information Criterion 988.8947 988.7203
Bayesian Information Criterion 992.8862 996.7032
Nomor 2