relationship between two factors

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

relationship between two factors

snowch
I have a dataset with two variables that are factors:

1) Decision Making Satisfaction (DMS), values = A - Completely, B -
Mostly, C - Partly, D - Not at all
2) IT Satisfaction values (ITS), values = A - Completely, B - Mostly, C
- Partly, D - Not at all

I would like to produce a table (matrix) and a chart of the factors,
with counts at the cross sections:

         A   B   C   D
A  
B       counts
C
D

How can I do this in R?

Many thanks,

Chris

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: relationship between two factors

Gregory Snow
The 'table' function will give you the simple counts.  Plotting a table
with the 'plot' function gives common charts for this.  The 'CrossTable'
function in the gmodels package creates the table along with additional
information.  There are a lot of other functions for creating/working
with tables depending on what you are trying to do.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
(801) 408-8111
 
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of christopher snow
> Sent: Thursday, December 06, 2007 5:51 AM
> To: [hidden email]
> Subject: [R] relationship between two factors
>
> I have a dataset with two variables that are factors:
>
> 1) Decision Making Satisfaction (DMS), values = A -
> Completely, B - Mostly, C - Partly, D - Not at all
> 2) IT Satisfaction values (ITS), values = A - Completely, B -
> Mostly, C
> - Partly, D - Not at all
>
> I would like to produce a table (matrix) and a chart of the
> factors, with counts at the cross sections:
>
>          A   B   C   D
> A  
> B       counts
> C
> D
>
> How can I do this in R?
>
> Many thanks,
>
> Chris
>
> --
> This message has been scanned for viruses and dangerous
> content by MailScanner, and is believed to be clean.
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: relationship between two factors

Marc Schwartz
In reply to this post by snowch

On Thu, 2007-12-06 at 12:51 +0000, christopher snow wrote:

> I have a dataset with two variables that are factors:
>
> 1) Decision Making Satisfaction (DMS), values = A - Completely, B -
> Mostly, C - Partly, D - Not at all
> 2) IT Satisfaction values (ITS), values = A - Completely, B - Mostly, C
> - Partly, D - Not at all
>
> I would like to produce a table (matrix) and a chart of the factors,
> with counts at the cross sections:
>
>          A   B   C   D
> A  
> B       counts
> C
> D
>
> How can I do this in R?
>
> Many thanks,
>
> Chris


See ?table, for example:

  table(DMS, ITS)

You did not indicate the type of chart you want to create, but some
possibilities, using base graphics, would be barplot(), dotchart() and
mosaicplot(). The latter is in the vcd package on CRAN.

HTH,

Marc Schwartz

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: relationship between two factors

John Kane-2
In reply to this post by snowch
?table should work

table (DMS, ITS)

I am not clear on what kind of chart you want.

will
plot(DMS, ITS) do what you want?


--- christopher snow <[hidden email]> wrote:

> I have a dataset with two variables that are
> factors:
>
> 1) Decision Making Satisfaction (DMS), values = A -
> Completely, B -
> Mostly, C - Partly, D - Not at all
> 2) IT Satisfaction values (ITS), values = A -
> Completely, B - Mostly, C
> - Partly, D - Not at all
>
> I would like to produce a table (matrix) and a chart
> of the factors,
> with counts at the cross sections:
>
>          A   B   C   D
> A  
> B       counts
> C
> D
>
> How can I do this in R?
>
> Many thanks,
>
> Chris



      Looking for the perfect gift? Give the gift of Flickr!

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: relationship between two factors

Henrique Dallazuanna
In reply to this post by snowch
Try this:

df <- data.frame(DMS=factor(rep(LETTERS[1:4], 10)),
ITS=factor(rep(LETTERS[1:4], 10)))
table(df)
plot(table(df))

--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O


On 06/12/2007, christopher snow <[hidden email]> wrote:

> I have a dataset with two variables that are factors:
>
> 1) Decision Making Satisfaction (DMS), values = A - Completely, B -
> Mostly, C - Partly, D - Not at all
> 2) IT Satisfaction values (ITS), values = A - Completely, B - Mostly, C
> - Partly, D - Not at all
>
> I would like to produce a table (matrix) and a chart of the factors,
> with counts at the cross sections:
>
>          A   B   C   D
> A
> B       counts
> C
> D
>
> How can I do this in R?
>
> Many thanks,
>
> Chris
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: relationship between two factors

David Winsemius
"Henrique Dallazuanna" <[hidden email]> wrote in
news:[hidden email]:

> Try this:
>
> df <- data.frame(DMS=factor(rep(LETTERS[1:4], 10)),
> ITS=factor(rep(LETTERS[1:4], 10)))
> table(df)
> plot(table(df))
>

That gave me simply 10's on the diagonals of the table and the plot was
not very satisfying. I suggest this alternate example:

tbl<-r2dtable(1,c=4*c(15,12,8,5),r=4*c(20,10,5,5))
tbl
#[[1]]
#     [,1] [,2] [,3] [,4]
#[1,]   27   23   21    9
#[2,]   18   11    5    6
#[3,]    8    6    2    4
#[4,]    7    8    4    1

# > class(tbl)
# [1] "list"
ITS=factor(rep(LETTERS[1:4]))
DMS=factor(rep(LETTERS[1:4]))
df<-data.frame(counts=unlist(tbl),expand.grid(DMS,ITS))
names(df)<-c("counts","DMS",   "ITS")
df
(df.tbl<-xtabs(counts~DMS+ITS,df))
#       ITS
#DMS  A  B  C  D
#      A 27 23 21  9
#      B 18 11  5  6
#      C  8  6  2  4
#      D  7  8  4  1
plot(df.tbl)

--
David Winsemius

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: relationship between two factors

snowch
In reply to this post by snowch
Thanks to everyone for their answers. What a helpful community!

christopher snow wrote:

> I have a dataset with two variables that are factors:
>
> 1) Decision Making Satisfaction (DMS), values = A - Completely, B -
> Mostly, C - Partly, D - Not at all
> 2) IT Satisfaction values (ITS), values = A - Completely, B - Mostly, C
> - Partly, D - Not at all
>
> I would like to produce a table (matrix) and a chart of the factors,
> with counts at the cross sections:
>
>          A   B   C   D
> A  
> B       counts
> C
> D
>
> How can I do this in R?
>
> Many thanks,
>
> Chris
>
>  


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.