多元统计与R语言第二次上机作业

setup, include
1
knitr::opts_chunk$set(echo = TRUE)

1.1

1
2
data1=read.csv('/home/fantasy/Desktop/r2/data/data1.csv',sep=',',header =F )
print(data1)

1.2

1
2
data2=read.csv('/home/fantasy/Desktop/r2/data/data2.csv')
print(data2)

1.3

1
2
data3=read.table('/home/fantasy/Desktop/r2/data/data3.csv',sep=',',header=F)
print(data3)

1.4

1
2
mydata=read.csv('/home/fantasy/Desktop/train.csv')
print(mydata)

2.

1
2
x=seq(0,100,1)
plot(x,x+1/x)

1
2
x=seq(1,100,0.001)
plot(x,exp(-(x^2)))

3.

1
2
x=rnorm(100,60,10)
x

1
t.test(x,conf.level=0.95)
1
t.test(x,mu=60)
1
t.test(x,mu=60,alternative = 'greater')
1
t.test(x,mu=60,alternative = 'less')
1
2
y=rnorm(100,0,1)
y
1
var.test(x,y,conf.level = 0.95)

4.1

1
binom.test(x=656,n=1000,p=1/2)

4.2

1
2
s=rexp(100,2)
s

1
t.test(s)

5.

1
2
data=read.csv('/home/fantasy/Desktop/r2/data/成绩单.csv')
data

1
2
3
4
5
6
chinese=c(data[,3])
math=data[,4]
english=data[,5]
mean(chinese)
mean(math)
mean(english)
1
2
3
var(chinese)
var(math)
var(english)
1
2
3
hist(chinese)
hist(math)
hist(english)
1
data
1
2
data[,2][data[,5][data[,3]>120 & data[,4]>120]]
mean(data[,5][data[,3]>120 & data[,4]>120])
1
2
3
total_score=data[,3]+data[,4]+data[,5]
data$total_score=total_score
data
1
2
3
4
5
6
eng1=data[,5][data[,'total_score']>300]
chinese1=data[,3][data[,'total_score']>300]
eng2=data[,5][data[,'total_score']<300]
chinese2=data[,3][data[,'total_score']<300]
print(cor.test(eng1,chinese1))
print(cor.test(eng2,chinese2))
凡希 wechat
喜欢所以热爱,坚持干货分享,欢迎订阅我的微信公众号
呐,请我吃辣条