当前位置:网站首页>R descriptive statistics and hypothesis testing

R descriptive statistics and hypothesis testing

2022-07-07 04:50:00 Mrrunsen

Descriptive statistics and hypothesis testing , First, let's introduce the factors , Then it introduces how to calculate common descriptive statistics 、 skewness 、 kurtosis 、 Correlation coefficient and contingency table , The hypothesis test part introduces the normality distribution test in turn 、 Homogeneity test of variance 、t test 、 Analysis of variance and commonly used nonparametric tests .

######################################################

#  factor 
set.seed(42)
l3 <-sample(letters[1:3], 10, replace = T)
l3
as.factor(l3)
factor(l3)
# factor()


#  Descriptive statistics 
set.seed(432)
d3 <- data.frame(
  ind = 1:1000,
  rn = rnorm(1000),
  rn2 = rnorm(1000, mean = 2, sd = 3),
  rt = rt(1000, df=5),
  rs1 = as.factor(sample(letters[1:3], 1000, replace = T)),
  rs2 = as.factor(sample(LETTERS[21:22], 1000, replace = T))
)

#  Descriptive statistics 
summary(d3)
library(skimr)
skim(d3)

#  skewness 
e1071::skewness(d3$rn)
#  kurtosis 
e1071::kurtosis(d3$rn2)

#  The correlation coefficient 
cor(d3$rn, d3$rt)
cor(d3[,2:4])
#  Correlation test 
cor.test(d3$rn, d3$rt)
library(psych)
corr.test(d3[,1:3])

#  Contingency table 
table(d3$rs1)
prop.table(table(d3$rs1))


######################################################
#  Hypothesis testing 

#  Normal distribution test 
# shapiro.test()
library(rstatix)
head(ToothGrowth)
原网站

版权声明
本文为[Mrrunsen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130747461232.html