This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
아래 R 코드는 카이제곱 분포를 그리는 내용으로 ChatGPT로 만든 내용이다.
chatGPT에 입력한 내용은 다음과 같다.
R에서 자유도가 5인 카이제곱분포의 분포값을 pchisq함수를 사용하여 가져오고, 이 자료로 그래프를 그린다. 그리고 상위 5%와 하위 5% 영역은 빨간색으로 색칠한다
# 필요한 패키지 설치 및 로드
if (!requireNamespace("ggplot2", quietly = TRUE)) {
install.packages("ggplot2")
}
library(ggplot2)
# 자유도가 5인 카이제곱분포 생성
df <- 5
x <- seq(0, 20, length.out = 1000)
y <- dchisq(x, df = df)
# 데이터 프레임 생성
data <- data.frame(x = x, y = y)
# 상위 5%와 하위 5% 임계값 계산
alpha <- 0.05
lower_critical <- qchisq(alpha, df = df)
upper_critical <- qchisq(1 - alpha, df = df)
# 그래프 생성
ggplot(data, aes(x = x, y = y)) +
geom_line(color = "blue") +
geom_area(data = subset(data, x <= lower_critical), aes(y = y), fill = "red", alpha = 0.5) +
geom_area(data = subset(data, x >= upper_critical), aes(y = y), fill = "red", alpha = 0.5) +
labs(title = "카이제곱 분포 (자유도 = 5)",
x = "값",
y = "밀도") +
theme_minimal()