依葫芦照抄了一个sas的程序,可以得到想要的结果了:
options pagesize=60 linesize=80 nodate nocenter nonumber;
data temp;
input sample pa pat;
cards;
1 300 20
1 320 50
1 800 30
2 300 50
2 320 20
2 800 30
;
run;
proc print;
quit;
proc freq data=temp;
table sample*pa/cmh;
weight pat;
run;
quit;
结果是:
The SAS System
Obs sample pa pat
1 1 300 20
2 1 320 50
3 1 800 30
4 2 300 50
5 2 320 20
6 2 800 30
The SAS System
The FREQ Procedure
Table of sample by pa
sample pa
Frequency|
Percent |
Row Pct |
Col Pct | 300| 320| 800| Total
---------+--------+--------+--------+
1 | 20 | 50 | 30 | 100
| 10.00 | 25.00 | 15.00 | 50.00
| 20.00 | 50.00 | 30.00 |
| 28.57 | 71.43 | 50.00 |
---------+--------+--------+--------+
2 | 50 | 20 | 30 | 100
| 25.00 | 10.00 | 15.00 | 50.00
| 50.00 | 20.00 | 30.00 |
| 71.43 | 28.57 | 50.00 |
---------+--------+--------+--------+
Total 70 70 60 200
35.00 35.00 30.00 100.00
Summary Statistics for sample by pa
Cochran-Mantel-Haenszel Statistics (Based on Table Scores)
Statistic Alternative Hypothesis DF Value Prob
---------------------------------------------------------------
1 Nonzero Correlation 1 0.0355 0.8506
2 Row Mean Scores Differ 1 0.0355 0.8506
3 General Association 2 25.5857 <.0001
Total Sample Size = 200
R里面的这段是计算趋势检验的:
R> table(lungtumor$dose, lungtumor$tumor)
0 1
0 38 2
1 43 7
2 33 15
R> ### Cochran-Armitage test (permutation equivalent to correlation
R> ### between dose and tumor), cf. Table 2 for results
R> independence_test(tumor ~ dose, data = lungtumor, teststat = "quad")
不过我按下面的来算也不对啊?
a=matrix(c(20,50,30,50,20,30),nrow=2,byrow=T)
rownames(a)=c(1,2)
colnames(a)=c(300,320,800) ##行和列名不影响最后结果的
x=as.table(a)
independence_test(object=x,teststat = "quad")
> x
300 320 800
1 20 50 30
2 50 20 30
data: Var2 by Var1 (1, 2)
chi-squared = 25.5857, df = 2, p-value = 2.781e-06
所以根本就没办法把 (300,320,800)的信息用上,pvalue也不是0.85.