前言:我是lst,这是本学期课程内容,根据上课内容、参考书本、CSDN社区等来源,完成的部分课程习题代码。如有问题,欢迎大家批评指正
library(openxlsx) #加载读取Excel数据包
#【输出设置】
#setwd("C:/Users/lst89/Documents/mvexer5") #设置目录
options(digits=4)
par(mar=c(4,4,2,1))
#第二章p57-2-1
R=matrix(c(1,0.8,0.26,0.67,0.34,0.8,1,0.33,0.59,0.34,0.26,0.33,1,0.37,0.21,0.67,0.59,0.37,1,0.35,0.34,0.34,0.21,0.35,1),nrow = 5,ncol = 5);
R #输入数据
solve(R) #求逆矩阵
R.e=eigen(R,symmetric=T) #symmetric是判断是否为对称阵,
R.e #求矩阵的特诊值
R.e $ vectors%*%diag(R.e $ values)%*%t(R.e $ vectors)#特征向量
#第二章p57-2-2
library(openxlsx) #加载读取Excel数据包
E2.2=read.xlsx('mvexer5.xlsx','E2.2');
E2.2 #读取mvexer5.xlsx表格E2.2数据
breaks = seq(0,3000,by = 300) #按组距为300编制频数表
breaks
hist(E2.2 $ X,breaks,col = 1:7,xlab = "工资(元)",ylab = "频数")#以工资x为横轴,频数y为纵轴,将数据划分为0-3000并以300为度量,绘制7列的彩色直方图
hist(E2.2 $ X ,breaks,freq = F,col = 1:7,xlab = "工资(元)",ylab = "频率")
Cumsum <- cumsum(E2.2 $ X)
cumsum
M <- seq(0,96000,by = 3000)
hist(Cumsum,M,freq = F,col = 1:12,las = 3,xlab = "工资(元)",ylab = "累积频率")#绘制出累计频率直方图
H = hist(E2.2 $ X,breaks = seq(900,3000,300))#正态概率图
names(H)
data.frame('组中距' = H $ mids,'频数' = H $ counts,'频率' = H $ density*300,'累积频率' = cumsum(H $ density*300))#