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.
library(MASS)
library(MASS)
data(anorexia)
summary(anorexia)
## Treat Prewt Postwt
## CBT :29 Min. :70.00 Min. : 71.30
## Cont:26 1st Qu.:79.60 1st Qu.: 79.33
## FT :17 Median :82.30 Median : 84.05
## Mean :82.41 Mean : 85.17
## 3rd Qu.:86.00 3rd Qu.: 91.55
## Max. :94.90 Max. :103.60
head(anorexia)
## Treat Prewt Postwt
## 1 Cont 80.7 80.2
## 2 Cont 89.4 80.1
## 3 Cont 91.8 86.4
## 4 Cont 74.0 86.3
## 5 Cont 78.1 76.1
## 6 Cont 88.3 78.1
ft<-anorexia[anorexia$Treat=="FT",]
weight<-c(ft$Prewt, ft$Postwt)
time<-c(rep("Before",nrow(ft)),rep("After",nrow(ft)))
ft_long<-data.frame(time,weight)
head(ft_long)
## time weight
## 1 Before 83.8
## 2 Before 83.3
## 3 Before 86.0
## 4 Before 82.5
## 5 Before 86.7
## 6 Before 79.6
str(ft_long)
## 'data.frame': 34 obs. of 2 variables:
## $ time : chr "Before" "Before" "Before" "Before" ...
## $ weight: num 83.8 83.3 86 82.5 86.7 79.6 76.9 94.2 73.4 80.5 ...
hist(ft$Prewt,
main="Weight Before Trearment",
xlab="Weight")
hist(ft$Postwt,
main="Weight After Treatment",
xlab= "Weight")
diff<-ft$Postwt-ft$Prewt
shapiro.test(diff)
##
## Shapiro-Wilk normality test
##
## data: diff
## W = 0.95358, p-value = 0.5156
t.test(ft$Postwt, ft$Prewt, paired=TRUE) # 같은 환자의 치료 전후 몸무게를 비교하는 대응표본,차이값이 정규분포 만족
##
## Paired t-test
##
## data: ft$Postwt and ft$Prewt
## t = 4.1849, df = 16, p-value = 0.0007003
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## 3.58470 10.94471
## sample estimates:
## mean difference
## 7.264706