0

我得到了关于 1960 年和 1970 年的原始数据,这些数据是关于前次生育的妇女将再生育一次的比例。我必须做一个 2 路分析表,然后是一个方形组合表来获得残差。我不知道如何在 R 中计算,所以它是手动完成的(按行中位数,然后按列中位数)。这是我对不同组的残差:

P0      P1      P2      P3      P4      P5
0.186   0.122   -0.014  -0.059  -0.017  0.013
-0.004  -0.004  -0.004  0.004   0.042   0.006
-0.174  -0.125  -0.013  0.018   0.048   0.012
0.205   0.176   0.043   -0.043  -0.052  -0.053
0.004   0.004   0.004   -0.004  -0.013  -0.069
-0.040  -0.011  0.009   0.005   0.013   -0.006

如何在 R 中输入,以创建茎叶和残差图。这些值是 1960 年第 1-3 行和 1970 年第 1-3 行数据的残差。

4

1 回答 1

1

To get row medians of a matrix a:

 apply(a,1,median)

To get column medians:

 apply(a,2,median)

To get overall median:

 median(a)

To combine the resulting row and column effects (say they're in vectors called roweff and coleff) into a matrix, outer(roweff,coleff,"+")

However, the command medpolish may also be useful in that it probably does mostly what you need.

To read the data in as a table (i.e. a matrix), use read.table, see the help under ?read.table

To read the data in as a vector, among other things you could scan it. See ?scan

To get a stem and leaf plot, see ?stem.

As my comment suggests, I can't tell what you want for a residual plot.

This information is covered in numerous documents. To get started, see the manual "An Introduction to R" that comes with R and is also freely available on the internet. There are a heap of beginner R documents to be found as well. One place to start is here

于 2012-12-10T22:07:06.867 回答