数学建模实验八

发布 2023-05-17 20:51:28 阅读 7022

(多元分析实验)

基本实验。解答:由于要分析血压与年龄两个变量之间的回归关系,可做一元回归,设年龄为自变量x,血压为因变量y.

1)设方程为:,(其中和是未知常数,为回归系数,服从正态分布)

利用r软件中的lm()可以非常方便地求出回归参数和,并作相应的检验,程序如下:

rm( list = ls ( all = true))

x = c(27,21,22,24,25,23,20,20,29,24,25,28,26,38,32,33,31,34, +37,38,33,35,30,31,37,39,46,49,40,42,43,46,43,44,46,47, +45,49,48,40,42,55,54,57,52,53,56,52,50,59,50,52,58,57)

y = c(73,66,63,75,71,70,65,70,79,72,68,67,79,91,76,69,66,73, +78,87,76,79,73,80,68,75,89,101,70,72,80,83,75,71,80,96, +92,80,70,90,85,76,71,99,86,79,92,85,71,90,91,100,80,109)

= lm(y ~ 1+x)

summary(

call:lm(formula = y ~ 1 + x)

residuals:

min 1q median 3q max

coefficients:

estimate std. error t value pr(>|t|)

intercept) 56.15693 3.99367 14.061 < 2e-16 **

x0.58003 0.09695 5.983 2.05e-07 **

signif. codes: 0 ‘*0.001 ‘*0.01 ‘*0.05 ‘.0.1 ‘ 1

residual standard error: 8.146 on 52 degrees of freedom

multiple r-squared: 0.4077, adjusted r-squared: 0.3963

f-statistic: 35.79 on 1 and 52 df, p-value: 2.05e-07

由结果可见,estimate项中给出了回归方程的系数估计,即,,这两个参数的估计还是比较准确的,都有“**即显著性比较好。该方程总体也通过了f统计数的检验,其p-value: 2.

05e-07<<0.05,由此得到的回归方程为:y=56.

15693+0.58003x

做残差分析,画出散点图:

op = par(mfrow=c(2,2), mar=.1+c(4,4,1,1), oma= c(0,0,2,0))

plot(fitted(

cex=1.2, pch=21, col="red", bg="orange",

xlab="fitted value", ylab="residuals")

plot(fitted(

cex=1.2, pch=21, col="red", bg="orange",

xlab="fitted value", ylab="standard residuals")

残差图:从图中可以看出,回归值的大小与残差的波动大小有关系,属于异方差情况,即等方差性的假设有问题。

2)正态性&方差齐次性检验。

shapiro-wilk normality test

data:

w = 0.9901, p-value = 0.9342

因此,残差满足正态性假设。

由上面残差图的结果可知,不满足方差齐次性的要求。

3)box-cox变换。

选取lambda为-2.0,作box-cox变换,然后重新计算残差散点图,如下图中的左下图,从图中可以看出残差散点图有很大改善,大部分点均匀落在标准化残差的2以内,满足齐次性要求。拟合后的曲线见右下图曲线。

总体程序如下:

rm( list = ls ( all = true))

x=c(27,21,22,24,25,23,20,20,29,24,25,28,26,38,32,33,31,34,37,38,33,35,30,31,37,39,46,49,40,42,43,46,43,44,46,47,45,49,48,40,42,55,54,57,52,53,56,52,50,59,50,52,58,57)

y=c(73,66,63,75,71,70,65,70,79,72,68,67,79,91,76,69,66,73,78,87,76,79,73,80,68,75,89,101,70,72,80,83,75,71,80,96,92,80,70,90,85,76,71,99,86,79,92,85,71,90,91,100,80,109)

op = par(mfrow=c(2,2), mar=.1+c(4,4,1,1), oma= c(0,0,2,0))

plot(fitted(

cex=1.2, pch=21, col="red", bg="orange",

xlab="fitted value", ylab="standard residuals")

library(mass)

#### 确定参数lambda

boxcox( lambda=seq(-10,2, by=0.01))

#### box-cox变换后, 作回归分析。

lambda= -2; ylam=(y^lambda-1)/lambda

summary(

#### 变换后残差与**散点图。

plot(fitted( rstandard(

cex=1.2, pch=21, col="red", bg="orange",

xlab="fitted value", ylab="standard residuals")

beta0=

beta1=

curve((1+lambda*(beta0+beta1*x))^1/lambda),

from=min(x), to=max(x), col="blue", lwd=2,

xlab="x", ylab="y")

points(x,y, pch=21, cex=1.2, col="red", bg="orange")

mtext("box-cox transformations", outer = true, cex=1.5)

par(op)

解答:1)设方程为:,(其中是未知常数,为回归系数,服从正态分布)

利用r软件中的lm()可以非常方便地求出回归参数,并作相应的检验,程序如下:

rm( list = ls ( all = true))

x1=c(44,40,44,42,38,47,40,43,44,38,44,45,45,47,54,49,51,51,48,49,57,54,56,50,51,54,51,57,49,48,52)

x2 = c(89.47,75.07,85.

84,68.15,814.27,77.

45,75.98,81.19,81.

42,81.87,73.03,87.

66,66.45,79.15,83.

12,81.42,69.63,77.

91,91.63,73.37,73.

37,79.38,76.32,70.

87,67.25,91.63,73.

71,59.08,76.32,61.

24,82.78)

x3 = c(11.37,10.07,8.

65,8.17,9.22,11.

63,11.95,10.85,13.

08,8.63,10.13,14.

03,11.12,10.6,10.

33,8.95,10.95,10,10.

25,10.08,12.63,11.

17,9.63,8.92,11.

08,12.88,10.47,9.

93,9.4,11.5,10.

5)x4 = c(62,62,45,40,55,58,70,64,63,48,45,56,51,47,50,44,57,48,48,67,58,62,48,48,48,44,59,49,56,52,53)

x5 = c(178,185,156,166,178,176,176,162,174,170,168,186,176,162,166,180,168,162,162,168,174,156,164,146,172,168,186,148,186,170,170)

x6 = c(182,185,168,172,180,176,180,170,176,186,168,192,176,164,170,185,172,168,164,168,176,165,166,155,172,172,188,155,188,176,172)

数学建模实验

实用数学建模与软件应用实验报告。学院名称 理学院专业年级 信计142班姓名 高梓涵学号 2014014515 课程 实用数学建模与软件应用报告日期 2016.11.9 问题重述 设某团体有n个单位,每个单位有人数a,总席位为s 现有席位p个待分配。问 各单位分配多少个席位是公平的?这就是席位公平分配...

数学建模实验

1 计算 汽车刹车距离 中的k值。解答过程 用最小二乘法来计算,过程如下 我们已知该曲线方程为d kv2 bv 令s 0 得出 0 0 得出 0 用matlab计算,其程序如下 x 29.3,44,58.7,73.3,88,102.7,117.3 y 42,73.5,116,173,248,343,...

数学建模实验

实验题目 人口类型。实验类型 基本操作。实验目的 掌握聚类分析的基本原理及方法。实验内容 要求学生在学习 掌握一些数学模型之后,能够理论联系实际,给出实际问题的相关数学模型,并能够编程求解,给出其结果。本次数学建模实习题目为 问题一 分析我国人口普查公报的相关数据,利用所学数学模型给出我国人口特征。...