margin.table( table(),<int> )——计算列联表的边际频数(边际求和),<int>=1为按列变量 addmargin.table(table(),<int> )——计算列联表的边际频数(边际求和)并求和,<int>=1为按列变量 as.formula(<string>)——转换为一个R公式,<string>是一个字符串 循环时的判断语句: ifelse(<test>, <yes>,...
prop.table(table(<data_var_1>, <data_var_2>),<int>)——比较两个data_var所占百分比,<int>填1位按行百分计算,2为列计算 margin.table( table(),<int> )——计算列联表的边际频数(边际求和),<int>=1为按列变量 addmargin.table(table(),<int>)——计算列联表的边际频数(边际求和)并求和,<in...
df<-data.frame(value=c(rnorm(10),rnorm(10,mean=1)),group=c(rep("control",10),rep("test",10)))# 进行的是 F 检验var.test(value~group,data=df)#>#> F test to compare two variances#>#> data: value by group#> F = 0.4, num df = 9, denom df = 9, p-value = 0.2#> alt...
用McNemar 卡方检验检验二维列联表的对称性。 ## Agresti (1990), p. 350. ## Presidential Approval Ratings. ## Approval of the President's performance in office in two surveys, ## one month apart, for a random sample of 1600 voting-age Americans. Performance <- matrix(c(794, 86, 150,...
(x)<-c(2,2) > chisq.test(x) Pearson's Chi-squared test with Yates' continuity correction data: x P 值<0.05 ,拒绝原假设,有影响。 列联数据的独立性检验: >y [,1] [,2] [,3] [1,] 45 12 10 [2,] 46 20 28 [3,] 28 23 30 [4,] 11 12 35 > chisq.test(y) Pearson's ...
var.test(x,y, ratio=1, alternative=c("two.sided","less","greater"), conf.level=0.95, ...) 3. prop.test(x,n, p=NULL, alternative=c("two.sided","less","greater"), conf.level=0.95, correct=TRUE) 三、非参数统计 1. 列联表分析使用卡方检验函数进行,需要事先把数据转化为矩阵形式,...
xtabs(formula,data) 根据一个公式和一个矩阵或数据框创建一个 N 维列联表 prop.table(table,margins) 依margins定义的边际列表将表中条目表示为分数形式 margin.table(table,margins) 依margins定义的边际列表计算表中条目的和 addmargins(table,margins) 将概述边margins(默认是求和结果)放入表中 ...
Affairs$ynaffair <- factor(Affairs$ynaffair,levels = c(0,1),labels = c("No","Yes")) / *将ynaffair转化为因子,levels有两个水平:0,1,对应得标签是No和Yes。*/ table(Affairs$ynaffair) / *计算ynaffair的频数,即二值型数据,可以用于logistics分析。*/ ...
对于二维列联表,table( )函数的使用格式为:mytable <- table(A, B) 其中A是行变量,B是列变量。xtabs( )函数还可使用公式风格的输入创建列联表,格式为:mytable <- xtabs(~ A + B, data=mydata) 其中mydata是一个矩阵或数据框。要进行交叉分类的变量应出现在公式的右侧(即~符号右方),以+作为分隔符...
二维列联表 # 对于二维列联表,table()函数的使用格式为: # mytable <- table(A, B) # 其中的A是行变量,B是列变量。除此之外,xtabs()函数还可使用公式风格的输入创建列联表, 格式为: # mytable <- xtabs(~ A + B, data = mydata) # 其中的mydata是一个矩阵或数据框。总的来说,要进行交叉...