-1

I am working on a project about weights for Screws.

I looped through and found the fits for a number of combinations like shown below.

head style       measurement  intercept     slope
a                1            x             1.0
a                2            x             2.2
a                3            x             4.1
b                1            x             1.2
b                2            x             2.0
b                3            x             4.1

If I know for a fact that the ones with the same measurement should have the same slope. So a-1 should have the same slope as b-1. Is there a way I could run another lm where I set the slopes to be a set number?

ajamess
  • 141
  • 2
  • 12
  • Add a reproducible example. – Robert Aug 01 '16 at 14:53
  • If head style doesn't matter in your model, don't include it in your model. You really should include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can see what you are really doing. – MrFlick Aug 01 '16 at 14:53
  • The head style determines the intercept only, while the measurement determines only the slope. My question is just if I can force the slope to be something and have lm just calculate the intercept. – ajamess Aug 01 '16 at 14:58
  • 1
    Model them together in one model. It's easy to have the same slope them. – Roland Aug 01 '16 at 15:12
  • Well, that variable determines the slope? Again, you should provide some sample input data and the code you are currently using to fit your model. It would be easier to offer specific advice with a a specific example. If you really have a question purely about statistical modeling, you might want to consider asking your question at [stats.se] instead. – MrFlick Aug 01 '16 at 15:23

1 Answers1

0

It's still not entirely clear what you're asking, but let's suppose your original data looks something like this:

head_style measurement  x  y
a          1            .  .
a          1            .  .
a          1            .  .
a          2            .  .
...
b          1            .  .

So what you've done so far is fit separate models (with y~x) to each combination of measurement and head_style. Now suppose you want slope to depend only on measurement and intercept to depend on both measurement and head_slope.

First, make sure measurement is a factor

my_dat <- transform(my_dat,measurement=factor(measurement))

Now fit a single lm model:

lm(y~head_style:measurement + measurement:x, data=my_data)

This should give you a separate intercept for each combination of head_style and measurement and a different slope for each value of measurement.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453