problems while correlating values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

problems while correlating values

Ahamarshan jn
Hi,
 I am a newbie to the world of R.

I have a data converted in csv format. Few cells in
some of the rows of the data are blank ( in the sense
that there is no value available for the particular
experiment). When i try to open the file in R. I get
an warning message.

The specific warning message i get is
{Warning message:
NAs introduced by coercion }

My data more or less looks like this

   - exp1 exp2 exp3 exp4 exp5 exp6
fish 20 10 40 30 - 10
duck 15 - 20 - - -
swan 10 5 7 12 15 -
kiwi 12 10 30 15 16 12
goat 18 10 20 - 10 -

{where '-' is blank spaces}

when I correlate this data using this
> round(cor(person.data,use="pairwise.complete.obs"))

correlation is done between experiments i.e. exp1,
exp2, exp3 etc whereas I need correlation to be done
row wise ie between fish,duck,swan,etc..

Another issue that I want to know of is, is there any
way to calculate the number of column pair's fills (N)
used in the correlation between data. ie for eg taking
these two values fish and duck

- exp1 exp2 exp3 exp4 exp5 exp6
fish 20 10 40 30 - 10
duck 15 - 20 - - -

it is in exp1 and exp3 that the values are available
and thus correlation is done only for these two exp's
hence we say N=2

like this between fish and swan N =4

- exp1 exp2 exp3 exp4 exp5 exp6
fish 20 10 40 30 - 10
swan 10 5 7 12 15 -

is there any way in R which would give me this value
of N between these Data used for correlation?

Also why is that an 'x' is introduced as a prefix to
the variable names when i compute with R is there any
way this can be removed?

Thank you
-ash#

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: problems while correlating values

Christian Ritz
Hi.

Try compute the correlation for the transposed data frame:

    cor( t(person.data), use="pairwise.complete.obs" )


Assuming that your data frame "person.data" contains NAs to indicate
where no value is available, I think the following computation yields N:

    (!is.na(person.data)) %*% t(!is.na(person.data))

using the functions "is.na", "!" (negation), "%*%" (matrix
multiplication) and "t" (matrix transpose). For details see their help
pages.

Christian

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html