第七期作业-线性回归R025

juan 2017-09-12 17:59:59 阅读: 1021
## R运行

#R语言运行代码如下:

x<-c(0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.19,0.20,0.23)

y<-c(42.0,43.5,45.0,45.5,45.0,47.5,49.0,53.0,50.0,55.0,55.0)

data1=data.frame(x=x,y=y)  #数据存入数据框

#拟合线性函数

lm.data1<-lm(y~ x,data=data1)

summary(lm.data1)        #输出拟合后信息

ab<-round(lm.data1$coefficients[1],3)  #回归方程系数a,保留3位小数
bb<-round(lm.data1$coefficients[2],3)  #回归方程系数b,保留3位小数
plot(data1$x,data1$y,xlab="x",ylab = "y",col="red",pch="*") #训练数据点
abline(lm.data1,col="blue")  #拟合曲线
text(mean(data1$x),max(data1$y),paste("y = ",bb,"x+(",ab,")",sep = ""))#方程式

#BAC蛋白浓度计算

a1<-c(0,0.0625,0.125,0.25,0.5,1)
a2<-c(0.079666667,0.098333333,0.124,0.162,0.251,0.410666667)
data2=data.frame(x=a1,y=a2) 

b1<-c(0.333,0.356,0.276,0.156)
b2<-c(0.322333333,0.356,0.271333333,0.153666667)
data3=data.frame(x=b1,y=b2) 

Model=lm(y~x,data=data2)

summary(Model)        #输出拟合后信息

ab<-round(Model$coefficients[1],3)  #回归方程系数a,保留3位小数
bb<-round(Model$coefficients[2],3)  #回归方程系数b,保留3位小数
plot(data2$x,data2$y,xlab="BAC method for protein concentraion measurement",ylab = "Concentraion(unit:ug/ul)",col="blue",pch=10) #训练数据点
abline(Model,col="blue")  #拟合曲线
text(mean(data2$x),max(data2$y),paste("y = ",bb,"x+(",ab,")",sep = ""))#方程式
legend("bottomright",legend = "R^2=0.9994")
m<-predict(Model,data3,interval="confidence")

points(b1,m[1:4],pch=c("A","B","C","D"),col="red")

结果TIM截图20170912175756.png

 
邀请讨论

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
{{item.nick_name}} 受邀请回答 {{item.create_time}}
{{item.refer_comment.nick_name}} {{item.refer_comment.create_time}}

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
切换到完整回复 发送回复
赞({{item.count_zan}}) 踩({{item.count_cai}}) 删除 回复 关闭
科研狗©2015-2024 科研好助手,京ICP备20005780号-1 建议意见

服务热线

178 0020 3020

微信服务号