Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

Let's say I'm running a model to look at questions asked on a form. My model looks like:

Price = B0 + B1(Gender) + B2(Age) + B3(Credit Type) + B4(Home) ...

I'm trying to calculate expected price for every possible scenario.

So price for gender = 0, age = 18, home = 1, etc.
Price for gender = 1, age = 18, home = 1, etc.
... and so forth

In R, is there a way to get the predicted price (output) for all possible combinations of the independent variables.

library(car)
mod = lm(sold ~ age + gender + marital + educ + cars + license + credit + type + home + id)
summary(mod)

EDIT: After reading some of the comments below, I realized the stupidity of what I was doing. But I'm still wondering if there's a way to find the expected price. A general measure of what would the price be given the values/variables in this model.

So lets that that from the model, is there a way to glean the expected price. Let's say that it's $10 given the model.

EDIT 2: Actually, just to figure it out in R, can anyone point to how I can perform the original task. The predicted value for all variations of the predictors.

share|improve this question
Surely age will be a CTN variable and not a factor? – csgillespie Dec 20 '11 at 21:58
age is a numeric variable. How does affect things? – ATMathew Dec 20 '11 at 22:08
That means that age can take infinitely values: 18, 18.00001, 18.00002,.... plus lots of values inbetween – csgillespie Dec 20 '11 at 22:20
1  
Hmm...20 ages times 2 genders times 3+ marital statuses times 3 to 20 or so levels of educational attainment times at least two "licenses" (whatever those are) times ... etc. = a minimum of 20,000 combinations (and likely millions). What useful purpose will this exponential explosion of numbers serve? – whuber Dec 20 '11 at 23:18
1  
That knowledge is compactly and efficiently expressed in terms of the fitted coefficients: in effect, they tell us everything that would be in that huge table of numbers you propose to compute and they are far more accessible. Therefore people usually publish those coefficients alone. To help with the interpretation, especially in communications with non-technical audiences, they sometimes provide the estimated value for a middle or typical combination of independent values and then explain the marginal-change interpretation of the coefficients themselves. – whuber Dec 21 '11 at 16:18
show 4 more comments

1 Answer

up vote 1 down vote accepted

Off the top of my head, you could build a data frame of all the possibilities via unique and expand.Grid:

all.x <- expand.grid(gender=unique(gender),age=unique(age),...)

Then pass all.x into the predict method for your model.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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