trinker (07-09-2012)
Hi Guys,
I am working on writing a R's script for Correspondence Analysis.....Yes, @Trinker, I am talking about a R's script
A number of packages are available to perform CA in R, and I am planning to pick the best from each one in order to provide users with a body of output statistics and graphs useful for CA interpretation.
I am faced with some issues I did not managed to solve on my own, so I would appreciate to have some guidance by someone of goodwill
The library is "ca" and the dataset coming with it is named "smoke".
The contingency table on which CA is performed is:Code:library(ca) data(smoke) summary(ca(smoke))
none light medium heavy
SM 4 2 3 2
JM 4 3 7 4
SE 25 10 12 4
JE 18 24 33 13
SC 10 6 7 2
The summary of CA analsis is as follows:
Principal inertias (eigenvalues):
dim value % cum% scree plot
1 0.074759 87.8 87.8 *************************
2 0.010017 11.8 99.5 ***
3 0.000414 0.5 100.0
-------- -----
Total: 0.085190 100.0
Rows:
name mass qlt inr k=1 cor ctr k=2 cor ctr
1 | SM | 57 893 31 | -66 92 3 | -194 800 214 |
2 | JM | 93 991 139 | 259 526 84 | -243 465 551 |
3 | SE | 264 1000 450 | -381 999 512 | -11 1 3 |
4 | JE | 456 1000 308 | 233 942 331 | 58 58 152 |
5 | SC | 130 999 71 | -201 865 70 | 79 133 81 |
Columns:
name mass qlt inr k=1 cor ctr k=2 cor ctr
1 | none | 316 1000 577 | -393 994 654 | -30 6 29 |
2 | lght | 233 984 83 | 99 327 31 | 141 657 463 |
3 | medm | 321 983 148 | 196 982 166 | 7 1 2 |
4 | hevy | 130 995 192 | 294 684 150 | -198 310 506 |
I have two (may be dumb) questions:
1) how can I ask R to return me the mumber of rows and columns of the contingency table?
2) how can I "extract" the values under the label "value" (highlighted in bold at the start of the CA summary above) in order to make some calculation on them: e.g., returning only the values that are greater than a given threshold.
Any guidance on these issues is welcome.
Thanks for your attention.
Regards
Gm
p.s.
sorry if the Thread's title is not so clear. On this respect, how the (package's) output appearing on the R console is actually named?
Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read -Groucho Marx-
trinker (07-09-2012)
@gianmarco, str and names can tell you a great deal about an output. Usually if you can't extract something it's because it's in a list and needs to be indexed as such (using [[index]] or [index])
This should give you what you're after:
Extracting certain values:Code:str(x) names(x) x[[1]] x[[2]] #or x[["rows"]] x[[3]] x[[3]][,2] x[[3]][2, ] nrow(x[[3]]) ncol(x[[3]]) dim(x[[3]])
I'd actually reassign:Code:#extract values greater than something x[[1]][, 2] # the column you asked about x[[1]][, 2] > .01 # seeing if it's greater than some other value #use that to select cases x[[1]][, 2][x[[1]][, 2] > .01] # from a vector x[[1]][x[[1]][, 2] > .01, ] # from a dataframe
if I had to type it alotCode:y <- x[[1]][, 2] > .01
"If you torture the data long enough it will eventually confess."
-Ronald Harry Coase -
gianmarco (07-09-2012)
Thank you so much Trinker!
I will read your hints and I will give a try, but I fear I will come back with further questions.....
Gm
Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read -Groucho Marx-
Please do, it's time I pay it forward.![]()
"If you torture the data long enough it will eventually confess."
-Ronald Harry Coase -
|
|