A whine and a request

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

A whine and a request

Vokey, John
guRus and useRs,

As I instruct my students: "With R what is difficult in anything  
else, is easy, usually one line of code; but, what is easy in  
anything else, is *&^%$%#$... (translation: next to impossible) in R."

I just ran into such a case that has, to put it mildly, driven me to  
use spreadsheets (if that is not a sign of complete desperation, I  
don't know what is).  It has nothing to do with particular versions  
of R or what OS I am using, but something more fundamental.  Here it  
is.  First, I have a very large data-set (the size, though, is not  
the issue) that at base has a single binary response (score 0/1) for  
each line of the data.  Different, large blocks of the data  
correspond to the responses of single participants to stimuli  
differing in feature x, where the distribution of particular  
differences in feature x is different for each participant. Table  
(and ftable) commands are great for reducing these data to isolate  
the Freqs with which particular x values occur within each  
participant, which is what I want, including how the frequency with  
which the participant responded 1 (or 0) to that level of feature x.  
So, assiduous use of table() gives me more or less what I want:  
within participant, the values of x, the associated frequencies of 0  
responses to those values of x, and the associated frequencies of 1  
responses to those values of x.  Now, what I WANT is the simple  
regression of the proportion of 1 responses (out of the sum of 0 and  
1 responses) to each value of x on the values of x.  What table()  
gives me is close, but useless, as I can't access the columns.  But,  
applying data.frame() to the results from table, gives me access to  
the columns as variables, but returns the (re)expanded data, which  
does not allow me to compute the simple proportions I want.  After  
too many hours of trying way too many desperate commands, I gave up.  
I printed the table(), copied it to the clipboard, pasted it into a  
spreadsheet, computed the proportions, fixed the header, saved it as  
a text file, and the read it back into R to do the regressions.  
There has got to be an easier way.
--
Please avoid sending me Word or PowerPoint attachments.
See <http://www.gnu.org/philosophy/no-word-attachments.html>

-Dr. John R. Vokey

______________________________________________
[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: A whine and a request

Liaw, Andy
I'm not sure if I understand your problem exactly, so I'm taking a wild
guess:  When you coerce a 2-d table object to data frame, what you get are
three columns: the two class variables and the frequencies.  If so, this
might help:
 
> x <- sample(1:2, 20, replace=TRUE)
> y <- sample(1:3, 20, replace=TRUE)
> tab <- table(x, y)
> as.data.frame(tab)
  x y Freq
1 1 1    2
2 2 1    2
3 1 2    7
4 2 2    2
5 1 3    3
6 2 3    4
> as.data.frame(unclass(tab))
  1 2 3
1 2 7 3
2 2 2 4

Andy

  _____  

From: [hidden email] on behalf of John Vokey
Sent: Wed 6/14/2006 2:53 AM
To: [hidden email]
Subject: [R] A whine and a request [Broadcast]



guRus and useRs,

As I instruct my students: "With R what is difficult in anything  
else, is easy, usually one line of code; but, what is easy in  
anything else, is *&^%$%#$... (translation: next to impossible) in R."

I just ran into such a case that has, to put it mildly, driven me to  
use spreadsheets (if that is not a sign of complete desperation, I  
don't know what is).  It has nothing to do with particular versions  
of R or what OS I am using, but something more fundamental.  Here it  
is.  First, I have a very large data-set (the size, though, is not  
the issue) that at base has a single binary response (score 0/1) for  
each line of the data.  Different, large blocks of the data  
correspond to the responses of single participants to stimuli  
differing in feature x, where the distribution of particular  
differences in feature x is different for each participant. Table  
(and ftable) commands are great for reducing these data to isolate  
the Freqs with which particular x values occur within each  
participant, which is what I want, including how the frequency with  
which the participant responded 1 (or 0) to that level of feature x.  
So, assiduous use of table() gives me more or less what I want:  
within participant, the values of x, the associated frequencies of 0  
responses to those values of x, and the associated frequencies of 1  
responses to those values of x.  Now, what I WANT is the simple  
regression of the proportion of 1 responses (out of the sum of 0 and  
1 responses) to each value of x on the values of x.  What table()  
gives me is close, but useless, as I can't access the columns.  But,  
applying data.frame() to the results from table, gives me access to  
the columns as variables, but returns the (re)expanded data, which  
does not allow me to compute the simple proportions I want.  After  
too many hours of trying way too many desperate commands, I gave up.  
I printed the table(), copied it to the clipboard, pasted it into a  
spreadsheet, computed the proportions, fixed the header, saved it as  
a text file, and the read it back into R to do the regressions.  
There has got to be an easier way.
--
Please avoid sending me Word or PowerPoint attachments.
See <http://www.gnu.org/philosophy/no-word-attachments.html
<http://www.gnu.org/philosophy/no-word-attachments.html> >

-Dr. John R. Vokey

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

______________________________________________
[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: A whine and a request

Jim Lemon
John Vokey wrote:
> Thanks.  But, as is common with e-mail communication, nobody seems to  
> have understood the issue I was whining about.

Indeed, I was totally wrong.

> So, here is an actual  
> case...
>
> Now, what I want is to regress the proportions of column(1)/(column(0)
> +column(1)) on x.  I can accomplish the proportions as follows:  
> props=tab[,2]/(tab[,1]+tab[,2]).  So, I want to regress props on the  
> *row labels* of tab.  But I can't seem to get them to be anything  *but*
> row labels.  For example,
>  > tab[,0]
>...
> extracts the row labels, *but still as labels*, not data.

as.numeric(rownames(tab))

Jim

______________________________________________
[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