close
/*
Simple linear regression 简单回归分析
Bar Chart、条形统计图
月薪和花红的关系。
*/
userName <- c("Lam Wei Wei", "Zheng Da Shi", "Lin Da You", "Fei Gu Man", "Chen Kuang", "Wong wei yun")
salary <- c(8500, 9800, 12500, 15000, 8700, 7500)
jobPosition <- c("Staff", "Manger", "BOSS", "CEO", "Staff", "Staff")
bonus <- c(2300, 1350, 3285, 1035, 3285, 1035)
#取得salary和bonus的图表
result <- data.frame(salary, bonus)
result
#用正态分布计算salary和bonus的方差
totalAmount.lm = lm(salary ~ bonus, data=result)
totalAmount.lm
#系数
coeffs = coefficients(totalAmount.lm);
coeffs
#bonus是3250的话、salary会是...?
newdata = data.frame(bonus=3250)
predict(totalAmount.lm, newdata)
salary bonus 1 8500 2300 2 9800 1350 3 12500 3285 4 15000 1035 5 8700 3285 6 7500 1035 Call: lm(formula = salary ~ bonus, data = result) Coefficients: (Intercept) bonus 10798.8760 -0.2273 (Intercept) bonus 10798.8759664 -0.2272787 1 10060.22
答案:salary是10060.
全站熱搜