0
$\begingroup$

Sorry about asking such a basic question.

Assuming I have data like this

x Trial1 Trial2 Trial3 1 1.0 2.0 3.0 2 1.1 2.1 3.1 3 1.2 2.2 3.2

How exaclty to I regress my predictor variable x onto my data. I was thinking naively that I could just take the average of the data trials and get something like

x y 1 1.1 2 2.1 3 3.1 for which I could simply use model <-lm(x ~ y). But I think I would introduce a bias by using the average. I was thinking instead to to create ordered pairs like (1,1.1), (1,2.0),...(3,2.2),(3,3.2). And use that for the regression but I'm not quite sure how to do this in a clean way in R. I was going to use data slicing and cbind a bunch of times, but I'm sure there is something better.

An example of what I'm getting at

The crux of my question is: how to do a regression model when you have data from mutiple runs of the same experiment. For example if I was looking at the temperature along a really thin metal wire (so its essentially 1-d), and then I mark off lenghts on this wire called x=0, x=1, x=2, ... x=total length. Then I take 10 temperature measuresments for each value of x. How do I create a regression model, which gives Temperarute as a function of length, i.e. T(x), given that I have 10 T values for each value of x?

$\endgroup$
  • $\begingroup$ Either your terminology is wrong or your model is written wrongly. Model formulas go y ~ x for response y and predictor x. $\endgroup$ – Glen_b Jun 27 '14 at 8:58
  • 1
    $\begingroup$ You have what's called "repeated measures." There's a good long explanation in the answer here: stats.stackexchange.com/questions/35590/… $\endgroup$ – shadowtalker Jun 27 '14 at 9:04
  • $\begingroup$ @Glen_b, Sorry that's just a typo. $\endgroup$ – user49105 Jun 27 '14 at 15:30
  • $\begingroup$ Can you please edit your question to clarify your actual meaning? $\endgroup$ – Glen_b Jun 27 '14 at 16:01
  • $\begingroup$ @Glen_b, The crux of my question is: how to do a regression model when you have data from mutiple runs of the same experiment. For example if I was looking at the temperature along a really thin metal wire (so its essentially 1-d), and then I mark off lenghts on this wire called x=0, x=1, x=2, ... x=total length. Then I take 10 temperature measuresments for each value of x. How do I create a regression model, which gives Temperarute as a function of length, i.e. T(x), given that I have 10 T values for each value of x? $\endgroup$ – user49105 Jun 27 '14 at 16:24
1
$\begingroup$

This is actually exactly the kind of data you're supposed to have for regression. Repeat observations at each value of X just means you have more information for that value of X. Just regress Temp on X, then you're modeling $\mathbb{E}[Y|X] = \alpha + \beta\cdot X$.

What you should do in this case, however, is check for clustering in your errors. The easiest way to do this is to run both a standard linear regression and a cluster-robust linear regression (Google how to implement it for your program of choice). If the coefficients are different, use the cluster-robust version. Basically what this is doing is saying "I suspect that observations taken from the same wire are not independent of each other," and if the suspicion here is correct then the estimates of standard errors (and therefore your p-values) will be inconsistent (that is, they do not converge to their "true" values as $n\rightarrow\infty$). This page has a bit more on how to interpret any differences between cluster-robust and classical ("homoskedastic") standard errors. It uses Stata as an example but the point is general.

However, that still assumes that the relationship (the value of $\alpha,\beta$) is the same for every wire. If you don't think that's a good assumption, or you're trying to test that assumption, this is the classic use case for a hierarchical/multilevel model.

I also made a write-up with R demos that you can read here.

| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Thanks very much. Yes I thought having multiple values for each x value was the point of regression. But then I was getting confused because of my deeply ingrained notions of functions and all that. But you're post removes any doubt. I'll tinker with R and figure out just how to do this, but I've got some ideas and you're link will help on that end as well. I can't upvote b/c of reputation, but I'll make a mental note to come back to this page once my rep goes up. Thanks again. $\endgroup$ – user49105 Jun 28 '14 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.