syneffort 3 years ago
parent fb6754aeac
commit ef2bc1789a
  1. 0
      Correllation/1.Correllation.r
  2. 0
      Correllation/2.Recursive.r
  3. 24
      Logistic Regression/1. LR.r
  4. 23
      PCA/1. pca.r
  5. 36
      analysis of variance/1. aov.r

@ -0,0 +1,24 @@
dose=c(1,1,2,2,3,3)
response=c(0,1,0,1,0,1)
count=c(7,3,5,5,2,8)
toxic = data.frame(dose, response, count)
toxic
out = glm(response~dose,
weights = count,
family = binomial,
data = toxic)
summary(out)
# Coefficients:
# Estimate Std. Error z value Pr(>|z|)
# (Intercept) -2.0496 1.0888 -1.882 0.0598 .
# dose 1.1051 0.5186 2.131 0.0331 *
# dose B = 1.1051 => Exp(1.1051) = 3.02
# dose 1 증가시 반응성 3.02배 증가한다고 볼 수 있음
# p-value = 0.03 < 0.05, 귀무가설 기각 => 약의 종류에 따라 반응이 다를 수 있음
plot(response~dose, data=toxic, type="n", main="Predicted Probability of Response")
curve(predict(out, data.frame(dose=x), type="resp"), add=TRUE)

@ -0,0 +1,23 @@
x1=c(26,46,57,36,57,26,58,37,36,56,78,95,88,90,52,56)
x2=c(35,74,73,73,62,22,67,34,22,42,65,88,90,85,46,66)
x3=c(35,76,38,69,25,25,87,79,36,26,22,36,58,36,25,44)
x4=c(45,89,54,55,33,45,67,89,47,36,40,56,68,45,37,56)
score = cbind(x1, x2, x3, x4)
colnames(score) = c("국어", "영어", "수학", "과학")
rownames(score) = 1:16
head(score)
result = prcomp(score) #주성분 고유벡터 출력
result
summary(result)
# Importance of components:
# PC1 PC2 PC3 PC4
# Standard deviation 30.1227 27.0528 9.07614 6.15239
# Proportion of Variance 0.5157 0.4159 0.04682 0.02151
# Cumulative Proportion 0.5157 0.9317 0.97849 1.00000
# PC2까지 누적 기여율 93.17%로 2개의 주성분 결정
# (일반적으로 80% 이상 되는 지점의 성분수를 주성분으로 결정함)

@ -0,0 +1,36 @@
install.packages("car")
library(car)
data(anorexia, package = "MASS")
anorexia
# levene 테스트로 등분산성 확인
leveneTest(Postwt~Treat, data = anorexia)
# > leveneTest(Postwt~Treat, data = anorexia)
# Levene's Test for Homogeneity of Variance (center = median)
# Df F value Pr(>F)
# group 2 1.7671 0.1785
# 69
# Pr(>F) = 0.1785, 0.05보다 크므로 귀무가설 채택 (등분산성 만족)
# 분산분석
out1 = aov(Postwt~Treat, data = anorexia)
out1
summary(out1)
# > summary(out1)
# Df Sum Sq Mean Sq F value Pr(>F)
# Treat 2 919 459.5 8.651 0.000444 ***
# Residuals 69 3665 53.1
# p-value 가 0.05보다 작으므로 귀무가설 기각 (각 집단 평균에 차이가 있음)
# ANOVA 분석
out2 = anova(lm(Postwt~Treat, data = anorexia))
out2
summary(out2)
# 일원 분산분석
out3 = oneway.test(Postwt~Treat, data = anorexia)
out3
summary(out3)
Loading…
Cancel
Save