Generate Data

Simulasikan 1000 data dengan 80% berdistribusi Gamma dan 20% berdistribusi Weibull

# Simulasi data Gamma
n_gamma <- 0.8 * 1000
data_gamma <- rgamma(n = n_gamma, shape = 2, rate = 0.5)  

# Simulasi data Weibull
n_weibull <- 0.2 * 1000  
data_weibull <- rweibull(n = n_weibull, shape = 2, scale = 8)

# Gabungkan data
curah_hujan <- c(data_gamma, data_weibull)
curah_hujan
##    [1] 10.60154071  4.93000435  1.23886549  1.19004010  2.96078601  1.13638147
##    [7]  3.39704559  0.80023330  3.91811000  7.31522682  3.05044876  2.29715380
##   [13]  3.80355238  6.25462159  2.68069293 12.06370066  3.46924234  5.97798425
##   [19]  3.23593678  4.78281761  5.30731378  1.71147754  2.57262685  2.08916414
##   [25]  0.80880854  6.27288907  2.05075577  1.53167309  1.24085359  4.45475058
##   [31]  3.16589149  8.52900392  1.06797287  0.26470412  5.09321445  0.78010271
##   [37]  4.96861669  8.54009008  4.16907301  5.78755240  4.02163960  6.88046256
##   [43]  0.38889227  3.85430785  5.63906463  0.17444953  0.57431093  0.57771306
##   [49]  5.10627577  0.70648085  1.45089283  5.02951400  3.72032299  2.94136399
##   [55]  5.38328392  0.96670565  3.24225565  2.78733953  2.61599364  0.44871821
##   [61]  4.67200330  4.54398987  0.50790215  5.62199919  7.75608665  3.09829075
##   [67]  2.05954825  0.31412045  3.00556461  5.56702773  4.63255383  2.43527164
##   [73]  2.65666856  3.17001916  5.72634846  7.02513992  6.50734232  6.90439529
##   [79]  0.35555846  2.15174872  2.17837577  4.13192644  0.63360761  6.34923510
##   [85]  1.41689988  4.89597091  1.84941976  6.55013841  2.12558844  1.99027560
##   [91]  3.86738738  4.49690660  0.37234289  0.50418179  3.19770214  2.74165387
##   [97]  3.13115130  3.36612400  8.77243623  0.47669069  6.53194141  4.33428203
##  [103]  4.70898637  2.09609375  1.87180669  1.62911667  0.74539155  4.49652266
##  [109]  3.91666299  1.38318334  4.92061776  4.69073578  5.56939223  3.13025493
##  [115]  3.91302634  5.19685163  7.90603424  2.98175222  6.43521847  2.26596310
##  [121]  8.08990992  3.97719201  0.70216150  4.19769341  0.71697116  4.11452344
##  [127]  3.58239082  1.98984854  3.11051376  3.35407132  2.20690755  4.01342001
##  [133]  2.86758953  4.45918383  0.99898183  2.06042448  5.23174542  2.21371473
##  [139]  5.93496097  4.80777343  6.62294528  1.09660606  2.08546178  0.90094633
##  [145]  5.41744686  5.76259790  0.40377080  4.70529593  1.66645383  2.72296783
##  [151]  5.60640021  5.93521115  3.01443809  2.34226162  1.94816338  4.03757393
##  [157]  5.61996265  1.99372813  1.43285349 11.40278934  0.93795009  3.54648204
##  [163]  2.01660828  8.26465346  8.48159846  5.84017576  4.13280364  1.08065387
##  [169]  3.65799439  5.80765243  7.12684623  4.07029506  8.83085492  3.00964111
##  [175]  7.02627028  7.12199281  1.21839676  7.77642496  5.11449110  2.21080030
##  [181]  4.58193869  7.89957288  5.72437093  1.64062955  6.13924920  3.78984308
##  [187]  7.25012256  1.18459105  2.71316906  4.11769311  5.82467099  5.36912742
##  [193]  1.86818034  6.56627912 12.38591036  6.43921695  1.57113303  2.70300240
##  [199]  1.36238100  5.05296257  2.21762056  3.49240263  2.70994803  3.62219337
##  [205]  3.19096832  0.97218738  1.86950668  3.64409443  0.90510766  6.08386509
##  [211]  4.08805168  3.01215615  1.07723317  3.51216836 10.52492588 14.14410514
##  [217]  0.80609974  3.26943996  2.03295606  9.41425923  3.34071728 11.69710360
##  [223]  3.93979271  6.31221086 13.50364191  2.46069099  4.43684715  0.22315606
##  [229]  5.28554488  1.48009527  4.67613036  3.52558445  2.12500188  1.81458165
##  [235]  3.51668710  3.56663081  3.79704291  2.11962541  1.35167598  2.39521857
##  [241] 10.46391085  3.39748591  4.12360623  6.92011178  1.72959523  5.52565592
##  [247]  7.14457565  2.03432465  7.47586539  7.97182458  4.19450513  8.26879151
##  [253]  2.84018205  5.74103967  8.72339534  1.37022853  8.06724673  2.55327709
##  [259]  1.79731786  6.26684489  6.15971463  3.22374667  2.45461409  7.51719336
##  [265]  2.41182488 10.77899617  1.68368706  4.87093146  6.08762962  5.34706243
##  [271]  3.44781346  0.28275540  9.30358212  4.03954432  4.99410102  1.44328485
##  [277]  8.47737633  3.81027775  2.17062602  5.73392462  4.54740188  2.53362825
##  [283]  4.19578029  1.10180326  6.86387342  1.61102062  1.67193580  2.90295948
##  [289]  9.24400555  1.12649222  3.08934870  1.68526641  6.11212526  3.32795151
##  [295] 11.73861915  0.27293069  1.10036215 11.46777032  0.85825174  6.84915402
##  [301]  1.94127590  1.34535822  1.53669961  6.15038655  1.80997230  3.06080398
##  [307]  1.03458431  5.69884958  4.41432603  4.47516303  8.15105790  4.25573014
##  [313]  3.45041831  1.56736348  2.84601506  0.84458829  4.77824916  2.41055046
##  [319]  3.78169449  2.35290356  2.56658598  1.16225607  4.84966069  1.44708481
##  [325]  3.80423671  3.19933008  1.81243764  1.33051836  1.01774397  1.90507167
##  [331]  3.28716211  5.58947961  5.03071150  3.68390493  1.63917200  5.98786401
##  [337]  3.60498355  1.85307865  2.51282739  5.33394259  1.23573032  2.91914965
##  [343]  2.13407937  4.30977659  2.22581290  2.68994361  4.18973445  5.32293893
##  [349]  2.43054315  2.68616322  0.85361203  4.93125408  4.15236257  4.23942076
##  [355]  1.10193243  0.25987107  6.88848962  2.94217911  1.92863366  6.44770781
##  [361]  1.43301278  2.64534537  2.05082621  6.49962359 13.11628903  2.84440827
##  [367]  3.72339417  0.96990672 10.88967779  2.15264323  6.64987420  3.04624938
##  [373]  4.27808293  1.26013591  2.34887814  3.27454874  7.28945990  1.04442963
##  [379]  4.67517708  3.38511138  9.11838216  2.68360643  4.97412546  0.43028595
##  [385]  8.58864380  2.82438195  1.75128707  2.14356708  7.75264629  3.13802266
##  [391]  1.23708982  7.05985426  3.77133020  3.90711115  5.74620236  2.62419475
##  [397]  2.21310739  4.25914277  4.82967489  2.69946835  6.78792415  2.95412417
##  [403]  5.76579677  2.55249694  1.67635723  1.09585063  4.77958984  8.85653086
##  [409]  1.98676158  4.22587891  5.61636331  0.68971059  5.72233684  3.41633006
##  [415]  3.55793448  1.75014802  2.31166855  4.09555468  2.64893402  2.82787737
##  [421]  0.64947917  4.74313643  4.02305671  0.67068633  3.11463781  2.54155301
##  [427]  1.66565944  5.10583846  6.37422804  8.70347846 11.73953076  4.73396393
##  [433]  6.07286557  7.06123525 11.58284556  5.30907067 12.05873076  1.33196288
##  [439]  3.17435271  3.21211236  5.37570566  0.34018188  1.73635471  2.57260600
##  [445]  0.32748457  2.23316466  5.22040156  4.10830252  5.35656470  3.53363004
##  [451]  5.28537180  3.45771212  2.24782413 10.63954251  4.46458463  3.78218644
##  [457]  3.24710487  4.07890225  2.57483505  1.14951946  5.02904565  8.14202295
##  [463]  4.32379945  9.03136709  4.98989223  1.11612772  3.12345664  3.84476949
##  [469]  2.62549682 10.34495373  3.26795119  2.67026967  1.95766043  1.60424007
##  [475]  1.30935547  3.54821125  4.18030922  7.61540462  2.64874850  2.71318294
##  [481]  1.47914414  4.76937088  5.62349984  5.28704511  0.74407550  5.01994149
##  [487]  8.51111760  4.15296544  2.03585006  3.29584422  4.05288423  6.30312372
##  [493]  7.22282343  5.55519379  6.39679462  3.09188792  2.23440606  9.99829080
##  [499]  5.05030405  1.41090299  4.84179026  1.54090492  2.42372547  5.80440289
##  [505]  2.14567396  3.00429885  5.94956202  9.48784393  4.18260747  4.25071817
##  [511]  3.37863067  3.09696245  6.58799829  5.79742982  5.19255923  7.43452906
##  [517]  4.33853246  3.67548915  6.16916717  5.33637860  1.07616439  0.71293861
##  [523]  0.50109320  0.48012880  3.40007632  0.83150711  7.61349438  0.93849039
##  [529]  3.42371009  2.94554662  1.77019204  4.26261194  0.45796838  5.83215885
##  [535]  3.94856272  4.58388485  0.93745584  2.03710912 12.72781563  5.75513114
##  [541]  0.99853772  3.52847455  1.34699786  6.33761777  4.35538658  3.23422361
##  [547]  1.19486177  1.84455704  0.46271553  1.55005501  2.68775208  1.03539002
##  [553]  0.52917691  0.91812577  2.16961354  0.95300046  4.08735701  2.50636246
##  [559]  6.64308894  2.62912598  3.16259217  1.54192173  9.84519535  1.34777708
##  [565]  0.55247711  9.57547703  3.95654356  4.32635382  2.63949378 12.94095560
##  [571]  1.63094490  5.98795420  4.82216012  2.22529784  3.55496848  5.23252941
##  [577]  2.99203207  6.96041118  6.34136892  2.08771939  2.05556534  1.82561442
##  [583]  4.69725999  1.12550152  3.16948804  3.25824131  1.88197127 10.37191231
##  [589]  2.59125499  5.79736628  1.82335926  4.98553687  0.44132332  0.33453194
##  [595]  2.03626272  4.42562853  7.92743292 10.15837794  3.21826772  2.37388260
##  [601]  1.85615521  1.56312093  2.64290709  3.51697393  2.29221888  1.26581200
##  [607]  5.11860828  5.71332803  4.01858773  3.07549959  0.97521184  8.04443770
##  [613]  2.15418733  4.08864414  4.80188663  1.76777330  1.41866054  4.02472006
##  [619]  2.33160272  4.86272461  4.07991367  4.63852549  4.24306429  2.61805061
##  [625]  4.22714480  1.85339373  7.33478451  1.67375141  3.40888318  8.50894278
##  [631]  6.24775901  0.52531847  3.97021937  9.86610133  3.07462200  1.87281567
##  [637]  4.35702568  6.52326970  8.13075657  7.93328936  0.80075078  5.04586118
##  [643]  0.68891566  6.15081258  1.61200513  1.86308303  6.58228988  1.79447669
##  [649]  7.77491269  1.66199285  1.91043843  3.20573056  2.65706487  3.38905827
##  [655]  3.92683424  4.76047401  1.69412152  1.99457416  2.64887045  0.35268105
##  [661]  1.22834986  0.70884075  6.04794099  3.11737959  4.56455126  1.66964954
##  [667]  3.45620891  3.64369220  1.99142142  4.38807361  1.42698049  1.67759657
##  [673]  7.41964330  2.92676344  7.54918543  4.43064423  9.36855489  8.21872456
##  [679]  0.62845575  4.25886760  3.94376020  6.12581585  1.08530634  0.84984967
##  [685]  5.17468011  3.58323769  1.39571142  0.04951099  2.79549594  0.63699191
##  [691]  4.44385027  4.13658894  3.79922951  2.54901706 10.88634624  2.66810428
##  [697]  1.75779738  3.86708584  1.64502471  4.02551262 12.97473966  6.67577808
##  [703]  6.04874182  3.10174272  3.99271053  3.28075314  3.98817335  1.40310929
##  [709]  1.07872010 10.25668393  3.42462136  7.67160105  6.14752413  1.59849260
##  [715]  2.54862444  2.80138813  4.29382262  3.33561866 11.00387879  3.45662705
##  [721]  1.94883614  6.32588225  2.51778925  2.07948263  2.09998749  1.14085565
##  [727]  6.78425673  2.99703743  5.18232530  4.48530192  4.38719736  3.75498376
##  [733]  5.25468279 10.07528337  4.75570337 11.49386188  2.92045989  0.76924122
##  [739]  4.04285867  1.46674790 12.03200717  0.56581747  0.97015319  4.62856133
##  [745]  3.99097709  3.03863011  3.40302721  3.28271373  7.09026625  0.72937210
##  [751]  7.19754110  3.69595477  2.14883257  4.18580770  7.51059577  4.03604187
##  [757]  3.08889348  7.36056809  4.23888109 10.71775001  0.78319155  3.26103746
##  [763]  2.71010188  5.23525298  1.43220165  2.07876726  0.51144913  0.91950171
##  [769]  3.49504848  1.10713472  9.28753141  6.38701206  9.59848504  2.57749138
##  [775]  9.48817134  6.51948576  1.83692683  2.36013056  5.89330923  1.42996884
##  [781]  4.09317909 10.75216984  0.90261222  1.60744523  7.34539162  1.24353927
##  [787]  5.44659084  4.86079483  4.38643251  7.76135339  2.97745086  3.38910838
##  [793]  1.22329389  0.56318608  3.89210603  9.99851142  6.20036054  5.59123888
##  [799]  5.17868979  2.05652379  5.40471029  1.22645796  2.65756089  9.83631602
##  [805] 13.70008163  1.23503305  8.02180576  3.11063722  8.75128182 15.08794929
##  [811]  9.92007996 14.29374455  8.23614273  2.52367195  9.36426860  8.86424630
##  [817] 11.32174413 11.63413135  3.56568645 15.14393290  2.17856890  7.96190252
##  [823]  9.50894343  4.88295131  2.47449558 11.56419783  7.52333356  6.25794415
##  [829] 10.69890256  2.54673406  5.62780347 10.51863297  1.57352941  4.38722666
##  [835]  1.27966365  6.33670020  5.40395712  5.48505484  5.39425461  5.18318453
##  [841]  7.17357422  4.58739294 11.45559205 10.01379712  3.33400003  7.78365992
##  [847]  6.40527500  5.58606237  5.88920575  0.96358742  9.48440833  2.49157240
##  [853]  2.59152097  4.40161356  6.86665232 10.36955432  6.03893049  0.68797335
##  [859]  4.30093177  4.32178648 10.83890394  9.87952656  6.37653958  8.28857992
##  [865]  4.45944222  4.41859834  5.99892825  9.80991511  8.48704258  5.07690118
##  [871]  6.86886027  5.51520333  8.37773226  9.44990884  1.61406054  5.43417749
##  [877] 14.69016644 14.21269581  3.74774952  3.61699409  4.87372237  8.60391697
##  [883]  5.21585803 13.68054274  2.36801760  7.28640165 14.00637525  9.46663183
##  [889]  5.15620702 13.85775525  6.75812819  4.74982075  2.48067816 10.32281256
##  [895]  6.26986370  6.47240295  7.98539916  4.02855509  3.10266614  2.17676290
##  [901]  5.79372808  3.52888930 12.42663682 12.52122580  9.91117848  3.54419893
##  [907]  4.17173323  7.35523371 14.93206834  5.60555348  8.44776205  3.16463144
##  [913] 11.18164288  7.91007949  3.13997795 14.40500278  8.79349196  7.13135790
##  [919]  2.46351237  2.83866827  8.67913531  1.64567126  6.21845378 11.15823904
##  [925] 10.29492138  5.92144051  9.16054643  1.80594249  8.57515925  3.39471732
##  [931]  4.75325214  3.50648945  2.51290659  9.11697531  4.77812928  5.67919926
##  [937] 12.63330594  1.97653520 12.13304282  7.01412710  9.83883041  4.62152012
##  [943]  7.63017010  9.44620683  5.41757667  7.19315229  5.59872416 15.43412207
##  [949] 10.29658826  5.12535304  9.18997567 11.12183499  3.81089957  2.96594768
##  [955]  8.20456784  8.71867257  3.31027790  4.85780839  2.27104694 12.15716942
##  [961]  5.27485607  6.67804233  9.57215352  3.26435226  6.49764022  8.09703582
##  [967]  4.56355185 10.01322553  3.43751890  4.80191879  9.86862851  5.86296359
##  [973]  2.45916098  7.59694049  3.45850596  2.16434787  6.44910573  8.34205889
##  [979]  4.25618087  4.39337910 13.31697446  1.77417901  6.46534282  3.72088600
##  [985]  1.28022860  2.96608283  7.44435063  5.95158334  6.99110665 16.92276324
##  [991]  5.48555224 11.63706695  2.64995320  1.71075067 15.53555268  8.39145232
##  [997]  7.19005478  3.92970186  3.84797676  1.83902049

Summary

summary(curah_hujan)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
##  0.04951  2.15380  3.91739  4.53284  6.11555 16.92276

Histogram

hist(curah_hujan, 
     main = "Histogram Curah Hujan", 
     xlab = "Curah Hujan", 
     col = "lavender", 
     border = "purple")

Data banyak terpusat di sebelah kiri

Boxplot

boxplot(curah_hujan, 
        main = "Boxplot Curah Hujan",
        ylab = "Curah Hujan",
        col = "pink",
        border = "black",
        outcol = "red")

Rentang data cukup kecil dan memiliki banyak outlier atas

Fitting Distribution

# FITDISTRPLUS
library(fitdistrplus)
## Warning: package 'fitdistrplus' was built under R version 4.3.3
## Loading required package: MASS
## Loading required package: survival
## Warning: package 'survival' was built under R version 4.3.3
library(logspline)
## Warning: package 'logspline' was built under R version 4.3.3
x = curah_hujan

## Fitting
wei_ = fitdist(x, "weibull")
gamma_ = fitdist(x, "gamma")
lnorm_ = fitdist(x, "lnorm")

plot(wei_)

plot(gamma_)

plot(lnorm_)

## Estimate parameters
print(wei_)
## Fitting of the distribution ' weibull ' by maximum likelihood 
## Parameters:
##       estimate Std. Error
## shape 1.511269 0.03695305
## scale 5.035287 0.11113078
print(gamma_)
## Fitting of the distribution ' gamma ' by maximum likelihood 
## Parameters:
##       estimate Std. Error
## shape 2.009211 0.08347012
## rate  0.443210 0.02089939
print(lnorm_)
## Fitting of the distribution ' lnorm ' by maximum likelihood 
## Parameters:
##          estimate Std. Error
## meanlog 1.2423432 0.02553616
## sdlog   0.8075243 0.01805667
## Summary Model
summary(wei_)
## Fitting of the distribution ' weibull ' by maximum likelihood 
## Parameters : 
##       estimate Std. Error
## shape 1.511269 0.03695305
## scale 5.035287 0.11113078
## Loglikelihood:  -2395.007   AIC:  4794.013   BIC:  4803.829 
## Correlation matrix:
##           shape     scale
## shape 1.0000000 0.3184947
## scale 0.3184947 1.0000000
summary(gamma_)
## Fitting of the distribution ' gamma ' by maximum likelihood 
## Parameters : 
##       estimate Std. Error
## shape 2.009211 0.08347012
## rate  0.443210 0.02089939
## Loglikelihood:  -2394.054   AIC:  4792.109   BIC:  4801.924 
## Correlation matrix:
##          shape     rate
## shape 1.000000 0.881004
## rate  0.881004 1.000000
summary(lnorm_)
## Fitting of the distribution ' lnorm ' by maximum likelihood 
## Parameters : 
##          estimate Std. Error
## meanlog 1.2423432 0.02553616
## sdlog   0.8075243 0.01805667
## Loglikelihood:  -2447.5   AIC:  4898.999   BIC:  4908.815 
## Correlation matrix:
##         meanlog sdlog
## meanlog       1     0
## sdlog         0     1

Distribusi Terbaik

# AIC
aic_values <- c(weibull = wei_$aic, gamma = gamma_$aic, lognormal = lnorm_$aic)
sorted_aic <- sort(aic_values); sorted_aic
##     gamma   weibull lognormal 
##  4792.109  4794.013  4898.999

Gamma merupakan distribusi yang paling sesuai

# BIC
bic_values <- c(weibull = wei_$bic, gamma = gamma_$bic, lognormal = lnorm_$bic)
sorted_bic <- sort(bic_values); sorted_bic
##     gamma   weibull lognormal 
##  4801.924  4803.829  4908.815

Gamma merupakan distribusi yang paling sesuai

# loglik
loglik_values <- c(weibull = wei_$loglik, gamma = gamma_$loglik, lognormal = lnorm_$loglik)
sorted_loglik <- sort(loglik_values, decreasing = TRUE); sorted_loglik
##     gamma   weibull lognormal 
## -2394.054 -2395.007 -2447.500

Gamma merupakan distribusi yang paling sesuai

Kesimpulan akhir : Gamma merupakan distribusi yang paling fit dengan data