# 단순회귀분석 result <- read.csv("testdata/drinking_water.csv") head(result) #귀무 : 제품의 가격수준을 결정하는 적절성은 만족도에 영향이 없다. #연구 : 제품의 가격수준을 결정하는 적절성은 만족도에 영향이 있다. x <- result$적절성 y <- result$만족도 df <- data.frame(x, y) df # 단순 선형회귀 모델 작성 model <- lm(formula = y ~ x, data = df) model <- lm(y ~ x, data = df) model plot(y ~ x) abline(model, col="red") options(scipen = 999) summary(model) # p-value < 0.05 연구가설 채택 #제품의 가격수준을 결정하는 적절성은 만족도에 영향이 있다. #y = 0.77886 + 0.73928 * x 0.77886 + 0.73928 * 10 #적절성이 10이라면 만족도는 8.17166라고 예측 plot(jitter(y, 5) ~ jitter(x, 5), data=df) sunflowerplot(df) # iris dataset data("iris") head(iris, 3) names(iris) cor(iris$Sepal.Length, iris$Sepal.Width) #음의 상관 cor(iris$Sepal.Length, iris$Petal.Length) #양의 상관 # 선형회귀 모델 model <- lm(Sepal.Length ~ Sepal.Width, data = iris) model summary(model) # 설명력 1.3% model2 <- lm(Sepal.Length ~ Petal.Length, data = iris) model2 summary(model2) # 설명력 76%