I want to use R to run a reaction-time experiment: Something appears on the screen, I respond by typing something (one keystroke), the system measures the speed of my response. R would be great for this if only I didn't have to hit Enter to enter that keystroke. I am doing such experiments now but they require two actions per trial: hit keystroke, hit Enter. Is there some way that R can be made to respond to a single keystroke (other than Enter)? -- View this message in context: http://www.nabble.com/using-R-for-a-reaction-time-experiment-tf4125643.html#a11732474 Sent from the R help mailing list archive at Nabble.com.
On 22-Jul-07 16:38:02, Seth Roberts wrote:> > I want to use R to run a reaction-time experiment: > Something appears on the screen, I respond by typing something > (one keystroke), the system measures the speed of my response. > R would be great for this if only I didn't have to hit Enter > to enter that keystroke. I am doing such experiments now but > they require two actions per trial: hit keystroke, hit Enter. > > Is there some way that R can be made to respond to a single > keystroke (other than Enter)?What operating system are you using? If it's Linux, there would be ways to detect the keystroke (say "A") and immediately send "A\n" (i.e. "A" followed by "enter") to a FIFO which R could be watching. Then R would receive your single keystroke as if you had followed it by pressing "Enter". If you're using Windows, then unfortunately I haven't a clue. Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 22-Jul-07 Time: 18:11:43 ------------------------------ XFMail ------------------------------
Psych grad student here, R user for 3 years. Using R for experiments is likely not advisable as it has no fine control of display timing (ex synching stimuli to the screen refresh, etc). On recommendation of colleagues I'm learning the Python language, which has a module called 'pygame' that is fantastic for psych experiments. Mike On 22-Jul-07, at 1:38 PM, Seth Roberts wrote:> > I want to use R to run a reaction-time experiment: Something > appears on the > screen, I respond by typing something (one keystroke), the system > measures > the speed of my response. R would be great for this if only I > didn't have to > hit Enter to enter that keystroke. I am doing such experiments now > but they > require two actions per trial: hit keystroke, hit Enter. > > Is there some way that R can be made to respond to a single > keystroke (other > than Enter)? > -- > View this message in context: http://www.nabble.com/using-R-for-a- > reaction-time-experiment-tf4125643.html#a11732474 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at stat.math.ethz.ch 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.-- Mike Lawrence Graduate Student, Department of Psychology, Dalhousie University Website: http://memetic.ca Public calendar: http://icalx.com/public/informavore/Public "The road to wisdom? Well, it's plain and simple to express: Err and err and err again, but less and less and less." - Piet Hein
try this: tol <- 0.000001 mat <- matrix(as.numeric(NA), 1000, 5) k <- 1 while(any(is.na(mat))){ x <- rnorm(1000, sd = 0.02) if (abs(mean(x)) < tol) { mat[, k] <- x k <- k + 1 } } abs(colMeans(mat)) par(mfrow = c(2, 3)) apply(mat, 2, hist) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Ing. Michal Kneifl, Ph.D." <xkneifl at mendelu.cz> To: "Rhelp" <r-help at stat.math.ethz.ch> Sent: Monday, July 23, 2007 4:40 PM Subject: [R] Help on "looping problem" needed!>I am wondering if someone could help me out with following problem: > I have written a for loop which generates a random normal > distribution > let us say 1000 times. > When the restriction is met (mean<0.000001), the loop stops, prints > the mean value and plots a histogram. > > for(i in 1:1000) { > a<-rnorm(1000,0,.2) > b<-abs(mean(a)) > if(b>.000001) next else {print(b);hist(a);break}} > > How to reshape the loop when I want to find at least 5 distibutions > that meet my restriction and save them (assign) under > names R1....R5. > Could you help me please? > > Michael > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Under windows you could use a graphics window for the stimulus and capture the keypress using the getGraphicsEvent function (this does not require hitting enter, but the graphics window needs to be the active window through the experiment). The playSudoku function in the sudoku package shows one example of using getGraphicsEvent to capture keypresses. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Seth Roberts > Sent: Sunday, July 22, 2007 10:38 AM > To: r-help at stat.math.ethz.ch > Subject: [R] using R for a reaction-time experiment > > > I want to use R to run a reaction-time experiment: Something > appears on the screen, I respond by typing something (one > keystroke), the system measures the speed of my response. R > would be great for this if only I didn't have to hit Enter to > enter that keystroke. I am doing such experiments now but > they require two actions per trial: hit keystroke, hit Enter. > > Is there some way that R can be made to respond to a single > keystroke (other than Enter)? > -- > View this message in context: > http://www.nabble.com/using-R-for-a-reaction-time-experiment-t > f4125643.html#a11732474 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >