- Nov 25, 2005
- 8,390
- 1
- 81
I am trying to fit two separate linear models to this problem:
Example of the data:
Price Pages Type
34.55 234 p
43.64 356 c
...
The items are either of type "p" or "c". I need to have two linear models, one for p and one for c. Each one has the same type of model.
The linear model I am fitting is:
Yi = beta0 + beta1 * Xi
Price = beta0 + beta1*Pages
So I used lm function as in our previous class examples. I have been trying to use the subset argument in lm() to do each one. I am only able to get one of them to work.. Any idea how to generate two models using subset argument?
Here is the code:
Example of the data:
Price Pages Type
34.55 234 p
43.64 356 c
...
The items are either of type "p" or "c". I need to have two linear models, one for p and one for c. Each one has the same type of model.
The linear model I am fitting is:
Yi = beta0 + beta1 * Xi
Price = beta0 + beta1*Pages
So I used lm function as in our previous class examples. I have been trying to use the subset argument in lm() to do each one. I am only able to get one of them to work.. Any idea how to generate two models using subset argument?
Here is the code:
Code:
lm(Price~Pages, , subset = Type)->model
abline(model$coef[1], model$coef[2])
summary(model)
Last edited:
