Dear all, this is not strictly R question. I have two vectors of different length (this is in the order of 10%). I am trying to see if still one can compare these two for similarity. IF the vectors were of the same length I would just take the difference of the two and plot a pdf of it. One way I am thinking is prorbably to find the longer length and short it in some way to get to the length of the short. Which are the math formulations for this type of problems and which of those R supports? Regards Alex [[alternative HTML version deleted]]
Berend Hasselman
2012-Mar-24 15:08 UTC
[R] Compare similarit of two vector of not same length
On 24-03-2012, at 12:44, Alaios wrote:> Dear all, > this is not strictly R question. I have two vectors of different length (this is in the order of 10%). I am trying to see if still one can compare these two for similarity. >What do you mean? - all entries in shorter vector occur in longer vector - the shorter vector is a sequence within the longer vector In the first case you could use %in% and all() In the second case see this discussion: http://r.789695.n4.nabble.com/matching-a-sequence-in-a-vector-td4389523.html https://stat.ethz.ch/pipermail/r-help/2012-February/303608.html Berend> IF the vectors were of the same length I would just take the difference of the two and plot a pdf of it. > > One way I am thinking is prorbably to find the longer length and short it in some way to get to the length of the short. > > > Which are the math formulations for this type of problems and which of those R supports? > > Regards > Alex > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
If you are trying to see if both vectors could be random samples from the same population then I would look at a qqplot (see ?qqplot) which will compare them visually (and if they are not the same length then the qqplot function will use interpolation to compare them. For a more formal test you can use the ks.test function (also can take vectors of different length), just note that a non-significant result does not mean that they are the same, and with big sample sizes this can be significant even though the differences are not practically meaningful. Another option is to do the qqplot along with the vis.test function in the TeachingDemos package, this lets you do a test based on the qqplot, but also gives you a feel for the practical difference. On Sat, Mar 24, 2012 at 5:44 AM, Alaios <alaios at yahoo.com> wrote:> Dear all, > this is not strictly R question. I have two vectors of different length (this is in the order of 10%). I am trying to see if still one can compare these two for similarity. > > IF the vectors were of the same length I would just take the difference of the two and plot a pdf of it. > > One way I am thinking is prorbably to find the longer length and short it in some way to get to the length of the short. > > > Which are the math formulations for this type of problems and which of those R supports? > > Regards > Alex > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com