Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

Mark Webb-5
P1 to Px are items purchased.
Data format in SPSS.
Id P1 P2 P3 P4
1  a    b   c    d
2  c    g
3  b    d

i.e. Person #1 buys items a,b,c,d.

I want to transform this into -

Id Item
1   a
1   b
1   c
1   d
2   c
2   g
3   b
3   d

Any suggestion on how to do this using syntax?
Regards
Mark Webb
--
Mark Webb

Line +27 (21) 786 4379
Cell +27 (72) 199 1000 [Poor reception]
Fax  +27 (86) 260 1946

Skype       tomarkwebb
Email       [hidden email] 
Reply | Threaded
Open this post in threaded view
|

Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

parisec
You can use the data restructure wizard and paste the syntax:
 
Data - Restructure - Restructure cases into variables.
 
IMHO, one of the most useful functions put into SPSS over the years.
 
Carol
 
 
 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mark Webb
Sent: Friday, September 28, 2012 8:22 AM
To: [hidden email]
Subject: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

P1 to Px are items purchased.
Data format in SPSS.
Id P1 P2 P3 P4
1  a    b   c    d
2  c    g
3  b    d

i.e. Person #1 buys items a,b,c,d.

I want to transform this into -

Id Item
1   a
1   b
1   c
1   d
2   c
2   g
3   b
3   d

Any suggestion on how to do this using syntax?
Regards
Mark Webb
--
Mark Webb

Line +27 (21) 786 4379
Cell +27 (72) 199 1000 [Poor reception]
Fax  +27 (86) 260 1946

Skype       tomarkwebb
Email       [hidden email] 
Reply | Threaded
Open this post in threaded view
|

Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

Bruce Weaver
Administrator
In reply to this post by Mark Webb-5
For the data set you show:

VARSTOCASES
  /MAKE Item FROM P1 P2 P3 P4
  /KEEP=id
  /NULL=DROP.

Result of a LIST command:

id Item

 1 a
 1 b
 1 c
 1 d
 2 c
 2 g
 3 b
 3 d

Number of cases read:  8    Number of cases listed:  8

The old-school (pre VARSTOCASSES) method would have been to use LOOP and XSAVE to create a new file.


Mark Webb-5 wrote
P1 to Px are items purchased.
Data format in SPSS.
Id P1 P2 P3 P4
1  a    b   c    d
2  c    g
3  b    d

i.e. Person #1 buys items a,b,c,d.

I want to transform this into -

Id Item
1   a
1   b
1   c
1   d
2   c
2   g
3   b
3   d

Any suggestion on how to do this using syntax?
Regards
Mark Webb

--
Mark Webb

Line +27 (21) 786 4379
Cell +27 (72) 199 1000 [Poor reception]
Fax  +27 (86) 260 1946

Skype       tomarkwebb
Email       [hidden email]
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

David Marso
Administrator
In reply to this post by parisec
"IMHO, one of the most useful functions put into SPSS over the years."

You can thank me for that !!!
Way back once upon a time in a former life I was a tek-sport rep at SPSS.
Among my numerous responsibilities was providing support for most of the odd data transformation/reshaping issues which came across the wire.  The principle share of these was either turning multiple vars into multiple cases or the reverse turning multiple cases into multiple variables.  If one searches the archives there is a veritable train wreck of code involving a VECTOR/AGGREGATE or VECTOR/LOOP/XSAVE combo.
After considerable time and effort and demonstration to the powers that be that much of my time was being spent walking people through these solutions it finally dawned upon the designers to create dialogs to achieve this amazing feat of data reshaping!


parisec wrote
You can use the data restructure wizard and paste the syntax:

Data - Restructure - Restructure cases into variables.

IMHO, one of the most useful functions put into SPSS over the years.

Carol



________________________________
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mark Webb
Sent: Friday, September 28, 2012 8:22 AM
To: [hidden email]
Subject: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

P1 to Px are items purchased.
Data format in SPSS.
Id P1 P2 P3 P4
1  a    b   c    d
2  c    g
3  b    d

i.e. Person #1 buys items a,b,c,d.

I want to transform this into -

Id Item
1   a
1   b
1   c
1   d
2   c
2   g
3   b
3   d

Any suggestion on how to do this using syntax?
Regards
Mark Webb

--
Mark Webb

Line +27 (21) 786 4379
Cell +27 (72) 199 1000 [Poor reception]
Fax  +27 (86) 260 1946

Skype       tomarkwebb
Email       [hidden email]<mailto:[hidden email]>
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

David Marso
Administrator
In reply to this post by Bruce Weaver
"The old-school (pre VARSTOCASES) method would have been to use LOOP and XSAVE to create a new file."
Or if one has numeric data use MATRIX with RESHAPE and avoid the hard disk clutter.  Strings can be used see below but they are a true pain to deal with in MATRIX without special considerations
MATRIX .
GET id / file * / var ID.
GET data / file * / var x1 to x4.
print data / FORMAT 'A8'.
compute ids=KRONEKER(id,make(nrow(data),1,1)).
print ids.
compute data=reshape(data,nrow(data)*ncol(data),1).
print data / FORMAT 'A8'.
save {ids,data}/var id x / strings x / outfile *.
end matrix.


I don't recall when V2C was spawned but it exists in ver 11.5 (circa early 2003).    
I left SPSS in late 2001 and helped with the design specs way before then.  
So by now I would imagine VARSTOCASES could be considered Old skool and the VECTOR/LOOP/XSAVE to be prehistoric.

Bruce Weaver wrote
For the data set you show:

VARSTOCASES
  /MAKE Item FROM P1 P2 P3 P4
  /KEEP=id
  /NULL=DROP.

Result of a LIST command:

id Item

 1 a
 1 b
 1 c
 1 d
 2 c
 2 g
 3 b
 3 d

Number of cases read:  8    Number of cases listed:  8

The old-school (pre VARSTOCASSES) method would have been to use LOOP and XSAVE to create a new file.


Mark Webb-5 wrote
P1 to Px are items purchased.
Data format in SPSS.
Id P1 P2 P3 P4
1  a    b   c    d
2  c    g
3  b    d

i.e. Person #1 buys items a,b,c,d.

I want to transform this into -

Id Item
1   a
1   b
1   c
1   d
2   c
2   g
3   b
3   d

Any suggestion on how to do this using syntax?
Regards
Mark Webb

--
Mark Webb

Line +27 (21) 786 4379
Cell +27 (72) 199 1000 [Poor reception]
Fax  +27 (86) 260 1946

Skype       tomarkwebb
Email       [hidden email]
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

Jon K Peck
In reply to this post by Mark Webb-5
I would like to point out that you can use the SPSSINC APRIORI extension command available from the SPSS Community website.  That command uses the R arules module but provides SPSS dialogs, syntax, and output.  It takes as input a set of dichotomous variables and finds the rules with the highest information content.



Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Mark Webb <[hidden email]>
To:        [hidden email]
Date:        09/28/2012 09:25 AM
Subject:        [SPSSX-L] Transforming SPSS data into Association Analysis/              Shopper Basket              format for arules in R
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




P1 to Px are items purchased.
Data format in SPSS.
Id P1 P2 P3 P4
1  a    b   c    d
2  c    g
3  b    d

i.e. Person #1 buys items a,b,c,d.

I want to transform this into -

Id Item
1   a
1   b
1   c
1   d
2   c
2   g
3   b
3   d

Any suggestion on how to do this using syntax?
Regards
Mark Webb

--
Mark Webb

Line +27 (21) 786 4379
Cell +27 (72) 199 1000 [Poor reception]
Fax  +27 (86) 260 1946

Skype       tomarkwebb
Email      
targetlinkmark@...
Reply | Threaded
Open this post in threaded view
|

Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

Bruce Weaver
Administrator
In reply to this post by David Marso
Gee, thanks David.  I really needed another reminder of my age right now.  In a lecture the other day, I showed some slides that featured Quick Draw McGraw & Baba Looey.  Not even *one* of the students recognized them!  (I suspect they've never heard of Snagglepuss is either.)  :-O


David Marso wrote
--- snip ---

I don't recall when V2C was spawned but it exists in ver 11.5 (circa early 2003).    
I left SPSS in late 2001 and helped with the design specs way before then.  
So by now I would imagine VARSTOCASES could be considered Old skool and the VECTOR/LOOP/XSAVE to be prehistoric.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

David Marso
Administrator
;-))
I must confess I grew up with those guys!  I was playing with my cat this AM and teasing her with 'I am the Master Cylinder' and I am going to fatten you up and eat you ... hahahhaaa (evil laugh).... My GF was wondering WTF?  Muttered 'she eats Daleks for breakfast'... I said that wasn't a Dalek it was Master Cylinder... She gave me blank stare (then I had to Google to determine which cartoon MC was part of).
OTOH:  I can claim (for reasons other than some of my more adventurous elders) that I can barely remember the 60's .  I suspect a more appropriate cartoon character for your slides these days might be Optimus Prime (maybe time for an update so you don't lose your audience).  I will let you stew on that and see if you can detect the intended joke/irony/thematic element to my suggestion.

Bruce Weaver wrote
Gee, thanks David.  I really needed another reminder of my age right now.  In a lecture the other day, I showed some slides that featured Quick Draw McGraw & Baba Looey.  Not even *one* of the students recognized them!  (I suspect they've never heard of Snagglepuss is either.)  :-O


David Marso wrote
--- snip ---

I don't recall when V2C was spawned but it exists in ver 11.5 (circa early 2003).    
I left SPSS in late 2001 and helped with the design specs way before then.  
So by now I would imagine VARSTOCASES could be considered Old skool and the VECTOR/LOOP/XSAVE to be prehistoric.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

parisec
In reply to this post by David Marso
Consider yourself thanked! Before this function, I didn't know how to write the code to flip a file so we got these things called undergrads to do it manually for us ;-)





-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Friday, September 28, 2012 9:37 AM
To: [hidden email]
Subject: Re: Transforming SPSS data into Association Analysis/ Shopper Basket format for arules in R

"IMHO, one of the most useful functions put into SPSS over the years."

You can thank me for that !!!
Way back once upon a time in a former life I was a tek-sport rep at SPSS.
Among my numerous responsibilities was providing support for most of the odd data transformation/reshaping issues which came across the wire.  The principle share of these was either turning multiple vars into multiple cases or the reverse turning multiple cases into multiple variables.  If one searches the archives there is a veritable train wreck of code involving a VECTOR/AGGREGATE or VECTOR/LOOP/XSAVE combo.
After considerable time and effort and demonstration to the powers that be that much of my time was being spent walking people through these solutions it finally dawned upon the designers to create dialogs to achieve this amazing feat of data reshaping!



parisec wrote

> You can use the data restructure wizard and paste the syntax:
>
> Data - Restructure - Restructure cases into variables.
>
> IMHO, one of the most useful functions put into SPSS over the years.
>
> Carol
>
>
>
> ________________________________
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of Mark Webb
> Sent: Friday, September 28, 2012 8:22 AM
> To:

> SPSSX-L@.UGA

> Subject: Transforming SPSS data into Association Analysis/ Shopper
> Basket format for arules in R
>
> P1 to Px are items purchased.
> Data format in SPSS.
> Id P1 P2 P3 P4
> 1  a    b   c    d
> 2  c    g
> 3  b    d
>
> i.e. Person #1 buys items a,b,c,d.
>
> I want to transform this into -
>
> Id Item
> 1   a
> 1   b
> 1   c
> 1   d
> 2   c
> 2   g
> 3   b
> 3   d
>
> Any suggestion on how to do this using syntax?
> Regards
> Mark Webb
>
> --
> Mark Webb
>
> Line +27 (21) 786 4379
> Cell +27 (72) 199 1000 [Poor reception] Fax  +27 (86) 260 1946
>
> Skype       tomarkwebb
> Email

> targetlinkmark@

> &lt;mailto:

> targetlinkmark@

> &gt;





-----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Transforming-SPSS-data-into-Association-Analysis-Shopper-Basket-format-for-arules-in-R-tp5715349p5715353.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD