आर में डेटासेट में गामा वितरण कैसे फिट करें


यह ट्यूटोरियल बताता है कि आर में डेटासेट में गामा वितरण को कैसे फिट किया जाए।

R में गामा वितरण फ़िट करना

मान लीजिए कि आपके पास नीचे दिए गए दृष्टिकोण का उपयोग करके एक डेटासेट z जेनरेट किया गया है:

 #generate 50 random values that follow a gamma distribution with shape parameter = 3
#and shape parameter = 10 combined with some gaussian noise
z <- rgamma(50, 3, 10) + rnorm(50, 0, .02)

#view first 6 values
head(z)
[1] 0.07730 0.02495 0.12788 0.15011 0.08839 0.09941

यह देखने के लिए कि गामा वितरण इस डेटा सेट z में कितनी अच्छी तरह फिट बैठता है, हम R में फिटडिस्ट्रप्लस पैकेज का उपयोग कर सकते हैं:

 #install 'fitdistrplus' package if not already installed
install. packages ('fitdistrplus')

#load package
library(fitdistrplus)

इस पैकेज का उपयोग करके वितरण को अनुकूलित करने के लिए उपयोग किया जाने वाला सामान्य सिंटैक्स है:

फिटडिस्ट (डेटासेट, डिस्ट्र = “आपकी पसंद का वितरण”, विधि = “डेटा फिट करने का आपका तरीका”)

इस मामले में, हम डेटा को फिट करने के लिए गामा वितरण और अधिकतम संभावना अनुमान दृष्टिकोण का उपयोग करके पहले उत्पन्न किए गए z डेटासेट को फिट करेंगे:

 #fit our dataset to a gamma distribution using mle
fit <- fitdist(z, distr = "gamma", method = "male")

#view the summary of the fit
summary(fit)

यह निम्नलिखित परिणाम उत्पन्न करता है:

फिर हम ऐसे ग्राफ़ तैयार कर सकते हैं जो निम्नलिखित सिंटैक्स का उपयोग करके दिखाते हैं कि गामा वितरण डेटासेट में कितनी अच्छी तरह फिट बैठता है:

 #produce plots
plot(fit)

यह निम्नलिखित प्लॉट तैयार करता है:

यहां वह पूरा कोड है जिसका उपयोग हमने R में डेटासेट में गामा वितरण को फिट करने के लिए किया था:

 #install 'fitdistrplus' package if not already installed
install. packages ('fitdistrplus')

#load package
library(fitdistrplus)

#generate 50 random values that follow a gamma distribution with shape parameter = 3
#and shape parameter = 10 combined with some gaussian noise
z <- rgamma(50, 3, 10) + rnorm(50, 0, .02)

#fit our dataset to a gamma distribution using mle
fit <- fitdist(z, distr = "gamma", method = "male")

#view the summary of the fit
summary(fit)

#produce plots to visualize the fit
plot(fit)

एक टिप्पणी जोड़ने

आपका ईमेल पता प्रकाशित नहीं किया जाएगा. आवश्यक फ़ील्ड चिह्नित हैं *