-5

Here's an example of my dataset in comma-delimited form (with variable names in the top row)...

LABEL,X,Y
bimmy,1,2
bimmy,2,4
bimmy,3,6
jimmy,2,8
jimmy,5,4
jimmy,6,10
marian,3,10
marian,4,9
marian,5,5

I want to do a linear regression analysis of X and Y, for each LABEL. So, I'd do an analyses of X and Y for 'bimmy', then for 'jimmy', then for 'marian'.

Is this possible in SPSS? Is it easier in R?

I've searched Google and Stack Overflow with a similarly-worded query, but found nothing relevant.

user1626730
  • 3,783
  • 5
  • 20
  • 24
  • Welcome (belatedly) to SO, the reason you are getting downvoted for this question is that it does not show any research effort. Also, asking `is it possible in SPSS` or easier is [not constructive](http://stackoverflow.com/faq#close) -- as the answer is obvious (or perhaps obvious to an R user) – mnel Mar 26 '13 at 02:56
  • I've searched Google and Stack Overflow with a similarly-worded query, but I've found nothing. – user1626730 Mar 26 '13 at 02:58
  • You could rephrase your question....... – mnel Mar 26 '13 at 03:00
  • What we're nudging you towards is the idea that you need to do some work yourself first before you start asking here. Figure out how to fit one linear model. Figure out how to write a for loop. Figure out how to split a data frame into groups. Make an attempt to put all that together. If you get stuck on _actual_ code in the process, _then_ come back and ask. – joran Mar 26 '13 at 03:01
  • The other reason you may be getting downvoted is that this is very poor practice from a statistical point of view .... even if it was taught to you in your second statistics class. – IRTFM Mar 26 '13 at 05:31
  • Ditto to what everyone else is saying in terms of research effort. In SPSS see the `SPLIT FILE` command. – Andy W Mar 26 '13 at 11:51

1 Answers1

5
yourdata <- read.table(text="LABEL,X,Y
bimmy,1,2
bimmy,2,4
bimmy,3,6
jimmy,2,8
jimmy,5,4
jimmy,6,10
marian,3,10
marian,4,9
marian,5,5",h=T,sep=",")

regression.to.repeat <- function( x ) lm( Y ~ X , data = x ) 

by( yourdata , yourdata$LABEL , regression.to.repeat )
Anthony Damico
  • 5,779
  • 7
  • 46
  • 77