Skip to content

Need help with use of ROCK algorithm in R for binary data

5 messages · Matej Zuzčák, PIKAL Petr, Nordlund, Dan (DSHS/RDA)

#
Dear list members,

I have one appeal for you. 

I need use ROCK (RockCluster) algorithm for binary data in R. My binary
data looks this:

|objects cat1 cat2 cat3 cat4 ...A TRUE FALSE FALSE FALSE B TRUE FALSE
TRUE FALSE C TRUE FALSE FALSE FALSE D FALSE TRUE TRUE TRUE E TRUE TRUE
TRUE TRUE F TRUE FALSE TRUE FALSE|

Now I need clasify these objects A-F to clusters. I apply this procedure
https://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/RockCluster#Dataset
But I have several problems.

 1. I import data from CSV file. |db <- read.csv(file="file.csv",
    header=TRUE, sep="|")| Fields are 1 (TRUE) and 0 (FALSE).
 2. I convert this data: |x <- as.dummy(db[-1]|). After this step all
    columns in x are duplicated with 1 and 0. Why? It is correct please?
 3. |rc <- rockCluster(x, n=4, debug=TRUE)|
 4. |rf <- fitted(rc)| Why |fitted| and when rather use |predict(rc, x)|?
 5. |table(db$objects, rf$cl)| After I get this output:

|    1   NA
A   1    0
B   1    0
C   1    0
D   0    1
E   0    1
F   0    1
|

What way I can read this output? What objects are in clusters with
other? What objects are the most similar please?

Many thanks for your help.
#
Hi

see in line
Better to show your data with dput command. Just copy the output of

dput(header(db, 20))

to your mail.
Hm. Why do you use csv if you set the separator to "|". I would use read.table.
Hm. Strange. In help page the result is TRUE/FALSE coding. Again posting real data would help us to understand your problem.

x <- as.integer(sample(3,10,rep=TRUE))
[1] 1 1 1 3 1 3 1 3 2 2
[,1]  [,2]  [,3]
 [1,]  TRUE FALSE FALSE
 [2,]  TRUE FALSE FALSE
 [3,]  TRUE FALSE FALSE
 [4,] FALSE FALSE  TRUE
 [5,]  TRUE FALSE FALSE
 [6,] FALSE FALSE  TRUE
 [7,]  TRUE FALSE FALSE
 [8,] FALSE FALSE  TRUE
 [9,] FALSE  TRUE FALSE
[10,] FALSE  TRUE FALSE
attr(,"levels")
[1] "1" "2" "3"

As I understand from help page, each columns is repeated the levels(column) times and each column in result has coding T/F based on that particular factor level.
There are only 2 clusters with levels 1 and NA. ABC belongs to cluster 1, DEF belongs to cluster NA. An what is the most weird, you have only 6 values in your db data ???

So again presenting your data either by dput or str is vital for evaluating your problem.

And BTW do not post in HTML, your messages are more or less scrambled.

Cheers
Petr
________________________________
Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a jsou ur?eny pouze jeho adres?t?m.
Jestli?e jste obdr?el(a) tento e-mail omylem, informujte laskav? neprodlen? jeho odes?latele. Obsah tohoto emailu i s p??lohami a jeho kopie vyma?te ze sv?ho syst?mu.
Nejste-li zam??len?m adres?tem tohoto emailu, nejste opr?vn?ni tento email jakkoliv u??vat, roz?i?ovat, kop?rovat ?i zve?ej?ovat.
Odes?latel e-mailu neodpov?d? za eventu?ln? ?kodu zp?sobenou modifikacemi ?i zpo?d?n?m p?enosu e-mailu.

V p??pad?, ?e je tento e-mail sou??st? obchodn?ho jedn?n?:
- vyhrazuje si odes?latel pr?vo ukon?it kdykoliv jedn?n? o uzav?en? smlouvy, a to z jak?hokoliv d?vodu i bez uveden? d?vodu.
- a obsahuje-li nab?dku, je adres?t opr?vn?n nab?dku bezodkladn? p?ijmout; Odes?latel tohoto e-mailu (nab?dky) vylu?uje p?ijet? nab?dky ze strany p??jemce s dodatkem ?i odchylkou.
- trv? odes?latel na tom, ?e p??slu?n? smlouva je uzav?ena teprve v?slovn?m dosa?en?m shody na v?ech jej?ch n?le?itostech.
- odes?latel tohoto emailu informuje, ?e nen? opr?vn?n uzav?rat za spole?nost ??dn? smlouvy s v?jimkou p??pad?, kdy k tomu byl p?semn? zmocn?n nebo p?semn? pov??en a takov? pov??en? nebo pln? moc byly adres?tovi tohoto emailu p??padn? osob?, kterou adres?t zastupuje, p?edlo?eny nebo jejich existence je adres?tovi ?i osob? j?m zastoupen? zn?m?.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
#
Hi,

thank you very much for your reply. :-)

- So I have really only four objects in this data set. It looks this:

objects cat1      cat2     cat3      cat4     ...
A           TRUE    FALSE   FALSE   FALSE
B           TRUE    FALSE   TRUE    FALSE
C           TRUE    FALSE   FALSE   FALSE
D           FALSE   TRUE    TRUE    TRUE
E           TRUE    TRUE    TRUE    TRUE
F           TRUE    FALSE   TRUE    FALSE

- I have modified standard separator for CSV file from comma to |
because I do other specific parsing and etc.  Original data have integer
values 1 (TRUE) and 0 (FALSE).

- Now I use this procedure for convert 1 and 0 on TRUE/FALSE coding (see
above) without duplicities:

dummyVar <- db[-1] > 0
x <- dummyVar

- Result is the same as in my previous mail. Result is the same (in my
last message) too when I use predict or fitted (rp <- predict(rc, x) /
rf <- fitted(rc)). Do you know what is different between predict and
fitted please? And what value of beta and theta parameter is optimal
please? So my clusters are: ABC - cluster 1, DEF - cluster NA. What is
means with "NA"? So these objects (ABC, DEF) are the most similar. I
will apply this algorithm on next set of data, it includes much more
objects... I will have question about Proximus algorithm yet (in next
mail), because it will be second algorithm for binary clustering of my
data sets... 

Thanks.
#
You should really go to the help page for the function rockCluster() and run the first example and study the output.  It should become clear that what you are calling the <NA> cluster is not a cluster at all.  It is an indicator of which objects *did not* cluster with any other objects ). 

In addition, you state you have only four objects.  This is confusing since you have a column in your data  named 'objects' which implies that you have 6 objects (and that is how many objects are in your cluster results).

The function, fitted() should be used with the data you are clustering.   If you want to "predict" what clusters NEW data would fall into, then use predict().  It is not surprising that predict() used on the original data would predict the fitted results.


Dan

Daniel Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services
#
Hello Dan,

many thanks for your reply. I have really 6 objects, I am sorry for my
mistake in my previous mail. So I will try use ROCK algorithm for next
data set and I will more study output yet.