R 统计推断

置信区间


有如下数据集求均值的置信区间

50,50,56,51,49,53,47,52,53,53,49,53,55,48,50,55

> cof_interval <- t.test(x,conf.level = 0.95) #t.test 对总体均值的区间估计
> cof_interval

    One Sample t-test

data:  x
t = 77.493, df = 15, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 50.08348 52.91652
sample estimates:
mean of x 
     51.5 

当然t.test还可以进行假设检验.

> t.test(x,mu=51.5,alternative = 'two.sided')

    One Sample t-test

data:  x
t = 0, df = 15, p-value = 1
alternative hypothesis: true mean is not equal to 51.5
95 percent confidence interval:
 50.08348 52.91652
sample estimates:
mean of x 
     51.5 

观测它的p-value.

正态性检验

这是进行t检验的前提

> shapiro.test(x)

    Shapiro-Wilk normality test

data:  x
W = 0.95762, p-value = 0.6188

成对数据检验

28.3,30.1,29,37.6,32.1,28.8,36,37.2,38.5,34.4,28,30
27.6,22.2,31,33.8,20,30.2,31.7,26,32,31.2,,

t.test

> t.test(x,y,alternative = "two.sided")

    Welch Two Sample t-test

data:  x and y
t = 2.1316, df = 18.171, p-value = 0.04694
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 0.05911817 7.80088183
sample estimates:
mean of x mean of y 
    32.50     28.57 

你可能感兴趣的:(R 统计推断)