Yes and no.

Thanks for that code, it was really useful, though not exactly what i was
getting at.

So I'm predicting sold on a number of independent variables.I'm trying to
find an estimated sold
price for each combination of the variables. So what is the expected sold
price for each possible
variable in the variables. For example:

Sold      age     gender    marital .......
3.50      18        M          No
5.20      18        F           Yes
3.20       19       M           No
14.01      20       F           No
....

So when I run the following code:

mod1 = lm(sold ~ age + gender + marital + educ2 + cars + license +
      credit + type + home + id, data=dat)

all.x <- expand.grid(age=unique(age), gender=unique(gender),
marital=unique(marital), educ2=unique(educ2),
                     cars=unique(cars), license=unique(license),
credit=unique(credit), type=unique(type),
                     home=unique(home), id=unique(id))

y.hat.new <- predict(mod1, newdata=all.x)
head(y.hat.new)
head(y.hat.new[!is.na(y.hat.new)])

I get this crazy result:

> head(y.hat.new[!is.na(y.hat.new)]) 2433025  2433026  2433027  2433028  
> 2433029  2433030
1491.941 1496.218 1500.495 1493.163 1498.051 1497.440


Just not sure what variation 2433025, etc stand for.














On Wed, Dec 21, 2011 at 3:18 AM, Tal Galili <tal.gal...@gmail.com> wrote:

> Hi Abraham,
>
> Isn't this what you wanted:
> data.frame(all.x, y.hat.new)
>
> p.s: it might be safer to use:
>
> myData
>
> mod1 = lm(sold ~ age + gender, data = myData)
>
>
>
>
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: tal.gal...@gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>
> ----------------------------------------------------------------------------------------------
>
>
>
>
> On Wed, Dec 21, 2011 at 12:04 PM, Abraham Mathew <abmathe...@gmail.com>wrote:
>
>>
>> I looked into what you suggested and got the following results.
>>
>> > y.hat.new       1        2        3        4        5        6        7    
>> >     8        9       10
>> 1144.675 1190.714 1236.753 1157.829 1210.445 1203.868 1128.232 1282.792 
>> 1246.619 1154.540
>>       11       12       13       14       15       16       17       18      
>>  19       20
>> 1197.291 1180.848 1253.196 1223.599 1243.330 1207.156 1220.311 1226.888 
>> 1164.406 1266.350
>>       21       22       23       24       25       26       27       28      
>>  29       30
>> 1161.117 1151.252 1272.927 1147.963 1230.176 1138.097 1286.081 1249.907 
>> 1177.560 1167.694
>>       31       32       33       34       35       36       37       38      
>>  39       40
>> 1289.369 1269.638 1170.983 1131.520 1240.042 1194.002 1276.215 1305.812 
>> 1213.733 1312.389
>>       41       42       43       44       45       46       47       48      
>>  49       50
>> 1309.101 1322.255 1121.655 1200.579 1263.061 1184.137 1174.271 1187.425 
>> 1259.773 1295.947
>>       51       52       53       54       55       56       57       58      
>>  59       60
>> 1233.465 1141.386 1292.658 1217.022 1332.120 1134.809 1124.943 1299.235 
>> 1318.966 1256.484
>>       61       62       63       64       65       66       67       68      
>>  69       70
>> 1345.274 1325.543 1315.678 1302.524 1279.504 1358.428 1091.997 1138.036 
>> 1184.076 1105.151
>>       71       72       73       74       75       76       77       78      
>>  79       80
>> 1157.767 1151.190 1075.554 1230.115 1193.941 1101.863 1144.613 1128.171 
>> 1200.518 1170.922
>>       81       82       83       84       85       86       87       88      
>>  89       90
>> 1190.653 1154.479 1167.633 1174.210 1111.728 1213.672 1108.440 1098.574 
>> 1220.249 1095.286
>>       91       92       93       94       95       96       97       98      
>>  99      100
>> 1177.499 1085.420 1233.403 1197.230 1124.882 1115.017 1236.692 1216.961 
>> 1118.305 1078.843
>>      101      102      103      104      105      106      107      108      
>> 109      110
>> 1187.364 1141.325 1223.538 1253.135 1161.056 1259.712 1256.423 1269.577 
>> 1068.977 1147.902
>>      111      112      113      114      115      116      117      118      
>> 119      120
>> 1210.384 1131.459 1121.594 1134.748 1207.095 1243.269 1180.787 1088.709 
>> 1239.981 1164.345
>>      121      122      123      124      125      126      127      128      
>> 129      130
>> 1279.443 1082.131 1072.266 1246.558 1266.289 1203.807 1292.597 1272.866 
>> 1263.000 1249.846
>>      131      132
>> 1226.826 1305.751
>>
>>
>>
>> What is this supposed to mean?
>>
>>
>>
>> mod1 = lm(sold ~ age + gender)
>>
>> all.x <- expand.grid(age=unique(age), gender=unique(gender))
>>
>> y.hat.new <- predict(mod1, newdata=all.x)
>> y.hat.new
>>
>>
>>
>> On Wed, Dec 21, 2011 at 1:43 AM, Tal Galili <tal.gal...@gmail.com> wrote:
>>
>>> combind
>>> ?predict
>>> and:
>>> expand.grid(weather=1:2,gender=c("male","female"))
>>>
>>>
>>>
>>>
>>>
>>> ----------------Contact
>>> Details:-------------------------------------------------------
>>> Contact me: tal.gal...@gmail.com |  972-52-7275845
>>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew)
>>> | www.r-statistics.com (English)
>>>
>>> ----------------------------------------------------------------------------------------------
>>>
>>>
>>>
>>>
>>> On Wed, Dec 21, 2011 at 6:59 AM, Abraham Mathew <abmathe...@gmail.com>wrote:
>>>
>>>> Lets say I have a linear model and I want to find the average expented
>>>> value of the dependent variable. So let's assume that I'm studying the
>>>> price I pay for coffee.
>>>>
>>>> Price = B0 + B1(weather) + B2(gender) + ...
>>>>
>>>> What I'm trying to find is the predicted price for every possible
>>>> combination of values in the independent variables.
>>>>
>>>> So Expected price when:
>>>> weather=1, gender=male
>>>> weather=1, gender=female
>>>> weather=2, gender=male
>>>> etc.
>>>>
>>>> Can anyone help with this problem?
>>>>
>>>> --
>>>> *Abraham Mathew
>>>> Statistical Analyst
>>>> www.amathew.com
>>>> 720-648-0108
>>>> @abmathewks*
>>>>
>>>>        [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> R-help@r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>>
>>
>>
>> --
>> *Abraham Mathew
>> Statistical Analyst
>> www.amathew.com
>> 720-648-0108
>> @abmathewks*
>>
>
>


-- 
*Abraham Mathew
Statistical Analyst
www.amathew.com
720-648-0108
@abmathewks*

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to