本文共 6127 字,大约阅读时间需要 20 分钟。
> summary(data) #min,lower quartile,median,upper quartile,max
> sapply(x,FUN,options) #mean,standard deviation,skewness,kurtosis#options:mean(),sd(),var(),min(),max(),median(),length(),range(),quantile(),fivenum()
> describe(data) #variable and observation amount,missing value and unique value mean, #quantile,,five min,five max
> stat.desc(data)#- basic=TRUE(default)#variable,null value,missing value,min,max,range,summary#- desc=TRUE(default)#median,mean,mean standard deviation,mean confidence interval(confidence=95%)#- norm=TRUE#normal distribution,include skewness and kurtosis(and degree of statistics)
> describe(data) #missing value mean,standard deviation,madian,trimmed mean, #median absolute deviation,min,max,range,skewness,kurtosis,standard error of the mean
> aggregate(data,by=list(INDICES),FUN) #return single statistic
> by(data,INDICES,FUN) #return multiple statistics
> summaryBy(formula,data=dataframe,FUN=function) #single or multiple grouping variable layering#formula = var1 + var2 + var3 + ... + varN ~ groupvar1 + groupvar2 + ... + groupvarN#(varN is numerical variable,groupvar is grouping variable)
> describeBy(data,list(INDICES)) #grouping variable are related
Function | Describe |
---|---|
table(var1,var2, ... ,varN) | N dimensional table |
xtabs(~formula,data) | N dimensional table is based on a formula,a matrix or data frame generating |
prop.table(table,margins) | convert frequency to scale |
margin.table(table,margin) | summary |
addmargins(table,margins) | add margins to table |
ftable(table) | tiled contingency table |
> CrossTable(data1,data2)
> chis.test(data) #p<0.01,related;p>0.05,unrelated
> fisher.test(mytable) #mytable is not a 2×2 table
> mantelhaen.test(mytable) #no third-order interaction
(1)Phi/Contingency/Cramer's V
> assocstats(mytable)
(2)Pearson/Spearman/Kendall
> cor(x,use,method) #default:use="everything",method="pearson"> cov(data) #covariance> cor.test(x,y,alternative= ,method= ) #test a relationship at a time> corr.test(x,use,method) #test multiple relationships at a time
use:
method:
> library(ggm)> pcor(u,S) #u:numerical vetor;S:covariance> pcor.test(r,q,n) #r:correlation coefficient;q:variable number;n:sample size
(1)parameter
1)independent sample> t.test(y~x,data) #t.test(y1,y2)
2)dependent sample
> t.test(y1,y2,paired=TRUE)
3)more than two groups:ANOVA
> aov(formula,data=dataframe)> TukeyHSD() #pairwise comparison
> data->manova(y~A)> summary.aov(data)> Wilks.test(y,shelf,method="mcd")
> fit.lm<-lm(y~A,data)> summary(fit.lm)
(2)nonparameter
> wilcox.test(y~x,data) #wilco.text(y1,y2)
#groups independent> kruskal.test(y~A,data) #groups dependent>friedman.test(y~A|B,data)
Function | Description |
---|---|
oneway_test(y~A) | two samples and K samples |
oneway_test(y~A | C) | containing a layering factor of two samples and K samples |
wilcox_test(y~A) | Wilcoxon-Meann-Whitney |
kruskal_test(y~A) | Kruskal-Wallis |
chisq_test(A~B | C) | Pearson Chi-square |
cmh_test(A~B | C) | Cochran-Mantel-Haenszel |
lbl_test(D~E) | linear correlation |
spearman_test(y~x) | Spearman |
friendman_test(y~A | C) | Friendman |
wilcoxsign_test(y1~y2) | Wilcoxon |
Function | Description |
---|---|
lmp(A~B,data=,perm=) | simple |
lmp(A~B+I(height^2),data=,perm=) | polynomical |
lmp(A~B+C+D+E,data=,perm=) | multiple |
avop(A~B,data=,perm=) | single factor variance |
avop(A~B+C,data=,perm=) | single factor covariance |
avop(A~B*C,data=,perm=) | double factor variance |
Function | Description |
---|---|
pwr.2p.test(h=,n=,sig.level=,power=) | two(n is equal) |
pwr.2p2n.test(h=,n1=,n2=,sig.level=,power=) | two(n are not equal) |
pwr.anova.test(k=,n=,f=,sig.level=,power=) | balanced single factor ANOVA |
pwr.chisq.test(w=,N=,df=,sig.level=,power=) | Chi-square test |
pwr.f2.test(u=,v=,f2=,sig.level=,power=) | generalized linear model |
pwr.p.test() | proportion(single sample) |
pwr.r.test(n=,r=,sig.level=,power=,alternative=) | correlation coefficient |
pwr.t.test(n=,d=,sig.level=,power=,type=,alternative=) | t est(single sample/two samples/pair) |
pwr.t2n.test(n1=,n2=,d=,sig.level=,power=,alternative=) | t test(n are not equal of two samples) |
END!
转载地址:http://ozfna.baihongyu.com/