/*
Simple linear regression 简单回归分析
假设花红是3250、经过预测月薪将是10060.22元。
图中红色就是预期花红和月薪的关系。
*/
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)
#用正态分布计算salary和bonus的方差
totalAmount.lm = lm(salary ~ bonus, data=result)
#系数
coeffs = coefficients(totalAmount.lm);
#bonus是3250的话、salary会是...?
newdata = data.frame(bonus=3250)
#预测
NewSalary <- predict(totalAmount.lm, newdata)
#画图
plot(result,
main = "Salary & Bonus Regression",
# lm(bonus ~ salary) bonus和salary要调转
abline(lm(bonus ~ salary), col = "red"),
col = "blue",
cex = 1.2,
pch = 16,
xlab = "Salary",
ylab = "Bonus" )
Call: lm(formula = salary ~ bonus, data = result) Residuals: 1 2 3 4 5 6 -1776 -692 2448 4436 -1352 -3064 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 10798.8760 3032.0350 3.562 0.0236 * bonus -0.2273 1.3374 -0.170 0.8733 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 3183 on 4 degrees of freedom Multiple R-squared: 0.007168, Adjusted R-squared: -0.241 F-statistic: 0.02888 on 1 and 4 DF, p-value: 0.8733 Min. 1st Qu. Median Mean 3rd Qu. Max. 10060 10060 10060 10060 10060 10060
留言列表