R의 데이터 세트에 감마 분포를 맞추는 방법


이 튜토리얼에서는 R의 데이터 세트에 감마 분포를 맞추는 방법을 설명합니다.

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에서 fitdistrplus 패키지를 사용할 수 있습니다.

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

#load package
library(fitdistrplus)

이 패키지를 사용하여 배포판을 조정하는 데 사용하는 일반적인 구문은 다음과 같습니다.

fitdist(dataset, distr = “분포 선택”, method = “데이터 피팅 방법”)

이 경우 데이터를 맞추기 위해 감마 분포와 최대 우도 추정 접근 방식을 사용하여 이전에 생성한 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)

의견을 추가하다

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다