Hi~ everyone!
For those who get following "warning" message:
> residual <- approval - predict.lm(lmfinal,data.approval)
Warning message:
longer object length
is not a multiple of shorter object length in: approval -
predict.lm(lmfinal, data.approval)
Try the 1.8.1 R version (I think some of us, including me till this morning, use 1.7.1
instead of 1.8.1). You may get the right result! (I found this a few hours ago...)
Young Hwan Kim
I should have r code that creates whatever output you reported.
-----Original Message-----
From: Alex Liebman [mailto:liebman@fas.harvard.edu]
Sent: Thursday, January 15, 2004 5:29 PM
To: jkline(a)fas.harvard.edu
Subject: small question
do you want r code and output, or just r code?
thanks,
alex
Some of you wanted to show you calculations for the math questions using
excel. If you use excel, include a file
Jacobkline.xls
Sorry to forget it the first time.
-----Original Message-----
From: Michael Richard Kellermann [mailto:kellerm@fas.harvard.edu]
Sent: Thursday, January 15, 2004 1:16 PM
To: Jacob Kline
Subject: Re: [gov1000-list] reminder about formats for exam materials
Jacob -
Just so I'm not missing something, what is the third file?
Mike
On Thu, 15 Jan 2004, Jacob Kline wrote:
> Class -
>
> By tomorrow midnight, I need to have three files from you named in a
> manner consistent with the following.
>
> Assuming that I am a student named "Jacob Kline"
>
> (1) jacobkline.doc
>
> This is write-up part of your final, either in MSWord, pdf, or rtf
> format. If you want to print it out and leave it my box, feel free.
>
> (2) jacobklineR.txt
>
> This file contains text which can be cut and paste into R. Notice that
> this is not the same as the R output you get when you run the code.
Use
> a text editor of some kind that is not MSWord to make this. Check
this
> file before sending it to me. Email it to yourself; go to a different
> computer; open it; cut and paste it into R. See that it gives the
same
> results you are giving me on your write-up.
>
> If your code is producing error messages, this is not the end of the
> world, as in you are not going to fail the exam. Try to show, in your
> comments, that you have done something to figure out why your code
> doesn't work.
>
> Hope you are well,
>
> Jacob
>
>
Class -
By tomorrow midnight, I need to have three files from you named in a
manner consistent with the following.
Assuming that I am a student named "Jacob Kline"
(1) jacobkline.doc
This is write-up part of your final, either in MSWord, pdf, or rtf
format. If you want to print it out and leave it my box, feel free.
(2) jacobklineR.txt
This file contains text which can be cut and paste into R. Notice that
this is not the same as the R output you get when you run the code. Use
a text editor of some kind that is not MSWord to make this. Check this
file before sending it to me. Email it to yourself; go to a different
computer; open it; cut and paste it into R. See that it gives the same
results you are giving me on your write-up.
If your code is producing error messages, this is not the end of the
world, as in you are not going to fail the exam. Try to show, in your
comments, that you have done something to figure out why your code
doesn't work.
Hope you are well,
Jacob
Paul pointed out to me that there is another easy way to get the
following error message
> Error in lm.fit(x, y, offset = offset, ...) :
> 0 (non-NA) cases
Earlier I said that if you get this, you have made a conceptual and not
a coding mistake.
Now, let me say that if you get this you have PROBABLY made a conceptual
mistake.
However, be sure that if you are using subset as an option to lm, the
subset you provide is a vector of indices or a logical vector.
If when you enter subset, you get 1s and 0s rather than TRUE and FALSE,
you need to tell lm
subset = as.logical(subset)
instead of subset = subset
Notice that the first command, which I have mostly used in the hw keys,
is always a good safeguard.
Sorry for any confusion this may cause.
Class -
I'm sorry but I am not going to answer any more questions about
calculating residuals. If you cannot change my code to make it work for
your model, then you should try to write your own code, but I can not
write the code for each of you, for each model.
If you do not understand what I did to make residuals, you can use the
residuals that come out of lm directly.
So let
Modela <- lm(approval~GDP)
Residuals <- Modela$residuals
Now residuals contains the residuals. I had some trouble manipulating
that object and decided to calculate them myself, to make sure I knew
what was going on. But unless you know what you are doing, I am afraid
that using the more involved procedure may mislead you.
Also - too many of you are relying on the code I gave you for Problem
Seven, Part Two. That code is much more complicated than the code I
gave you for Problem Seven, Part One. If you don't understand how to
use the second code, then stick with the method of the first. It is more
important that you know what you are doing and it is easier to know what
you are doing with the earlier approach. Whatever code you use, be sure
that you understand what it does and be sure to justify its use.
Hope you are well,
Jacob
Class -
Some of your papers are in my mailbox and have been there for some time.
Tomorrow morning, I am going to remove them (to make room for the
finals) so please retrieve as you like before then.
Hope you are well,
Jacob
For some reason, I didn't have this problem on my code. The problem is
the lagapproval1 is NA on the first entry and inflationtp4 is missing
the last 5 observations.
So here's the fix.
Before you run the troublesome line, you need to write the line
usable <- which(!is.na(lagapproval1)&!is.na(inflationMonthlytp4)) %in%
usable
Then in the troublesome line replace approval
With approval[usuable]
That line basically keeps track of any places where the variables go to
NA and then exclude them from the calculation of the residuals.
-----Original Message-----
From: Kai-Hua Yu [mailto:kyu@fas.harvard.edu]
Sent: Wednesday, January 14, 2004 5:05 AM
To: Jacob M. Kline
Subject: residuals / predict.lm error
Hi Jacob,
I'm running your HW7 code exactly as in the key and getting this
message:
> residual <- approval - predict.lm(lmfinal,data.approval)
Warning message:
longer object length
is not a multiple of shorter object length in: approval -
predict.lm(lmfinal, data.approval)
I know you brought it up on the list but I'm not sure what the solution
is. You mentioned running length() commands to check for discrepancies,
and I found that length(predict.lm(lmfinal, data.approval)) gives me
565, as opposed to 570 for the whole approval set. Incidentally I'm
asking this because I have a similar problem on my own dataset.
I can't figure out how predict.lm works after reading the code/help, but
I'm guessing this has something to do with NAs in the dataset, as in the
lag/future variables that go outside the original, because lmfinal
includes a lagapproval1 that has a NA at the beginning and an
inflationMonthlytp4 with 4 NAS at the end. Am I right? And how can I
deal with this so I can still do the residual plot?
Thanks,
Kai-Hua
--
~-~-~-~-~-~-~-~-~-~-~-~-
Kai-Hua Yu
364 Currier Mail Center
Cambridge, MA 02138
(617) 493-6916
Currier House, Gilbert 416
Many of you are encountering the following error message:
Error in lm.fit(x, y, offset = offset, ...) :
0 (non-NA) cases
The good new indicates that if you have gotten this far, you have
probably coded everything correctly.
The bad news is that it indicates a conceptual error on your part.
The command 'lm' only looks at observations (rows of data) which do not
contain an NA for any variable (columns of data).
The error message means that for every observation, at least one
variable in your model contains an NA. That is a problem you created
and not a problem with R.
Hope this is helpful,
Jacob
I don't know how to convert the GDP values into monthly values; you'd
have to be more specific. The GDP values are quarterly values -
As for making quarterly data -- you have to think about this yourself.
We talked about this a bit in the work on Homework 7, part one. What
should approval be for the quarter? How about inflation? Unemployment?
You have to ask a more specific coding question to get code in response.
-----Original Message-----
From: Kelly Ann Sarabyn [mailto:sarabyn@fas.harvard.edu]
Sent: Saturday, January 10, 2004 8:15 PM
To: jkline(a)fas.harvard.edu
Subject: gov1000
jacob,
i'm trying to check for linearity with the R method you wrote in HW7.
however, for GDP and approval it produces an NA because of all the NAs
in the
GDP data. is there a way to either convert the approval data into
quarters
(say averaging every 3 months) or better yet a way to convert the GDP
data
into monthly values?
thanks,
kelly