---
title: "R Notebook"
output:
html_document:
df_print: paged
html_notebook: default
pdf_document: default
---
```{r}
library(ISwR)
attach(thuesen)
lm(short.velocity~blood.glucose)
head(thuesen)
#thuesen
y <- lm(short.velocity~blood.glucose)
summary(y) #回归结果 概要输出
anova(y) #回归方差分析
plot(blood.glucose,short.velocity)
#abline(lm(short.velocity~blood.glucose))
abline(1.3,.022) #截距、斜率画直线
segments(blood.glucose,fitted(y),blood.glucose,short.velocity)
cc <- complete.cases(thuesen) #处理缺失值
thuesen[cc,] #另外一个方法处理缺失值,更好
#options(na.action=na.exclude)
pred.fram <- data.frame(blood.glucose=4:20)
pp <- predict(y,int="prediction",newdata=pred.fram) #直线预测数据
pc <- predict(y,int="confidence",newdata=pred.fram) #可信区间预测
plot(blood.glucose,short.velocity,ylim = range(short.velocity,pp,na.rm = T))
pred.gluc <- pred.fram$blood.glucose
matlines(pred.gluc,pc,lty = c(1,2,2),col = "black") #矩阵绘制线图
matlines(pred.gluc,pp,lty = c(1,3,3),col = "black")
```