Reputation:
I was given raw data on 1960 and 1970 ratio of women number of previous birth who will have another birth. I had to do a 2-way analysis table then a square combining table to obtain the residuals. I did not know how to compute in R, so it was done manually (by row medians and then column medians). This was my residuals for the different groups:
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
how do I enter in R, to create a stem and leaf and residual plot. These values are the residuals for the data for 1960 row1-3 and 1970 row 1-3.
Upvotes: 0
Views: 159
Reputation: 8282
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
Upvotes: 1