Hi Maria,
I am forwarding your email to the class list as we have received a few
emails like this.
The time stamp for problem sets is determined by when you upload your
write-up and R code to the online problem set drop box. So, it does not
matter whether you submit your hard copy at the 7pm or 8pm section.
Thanks,
Miya
---------- Forwarded message ----------
From: Loumioti, Maria <mloumioti at hbs.edu>
Date: Thu, Feb 12, 2009 at 11:47 AM
Subject: pr set
To: "woolfalk at fas.harvard.edu" <woolfalk at fas.harvard.edu>
Hi Miya
I am coming to the section tonight at 8. Is it ok to handle in the problem
set at 8 in the section or should I do it in advance? The problem is that I
live a bit far away and it would take me some time to go back and forth
twice.
Thx
Maria Loumioti
HBS Doctoral Student
Accounting &Management
Tel: +1-617-852-0570
--
Miya Woolfalk
Ph.D. Student
Harvard University
Government and Social Policy
I didn't take the statistics class last semester, but various folks have
suggested that Gov2001 is the right course for me on inference.
In trying to compute the coefficients, I've been first appending a column
of 1s at the start of the X data. Then after appending these 1s, I run the
formula for Beta-hat, when I invert (solve) for X-prime times X it tells me
either that
Error in solve.default...: system is computationally singular:
reciprocal condition number = 2.09476e-18
or
Lapack routine dgesv: system is exactly singular
I've been trying to set the coefficients to
coeff<-solve(t(x)%*%x)%*%(t(x)%*%y)
There must be something obviously wrong with the formula since it can't
even solve a really simple regression problem I give it, to say nothing of
the PS1_Data file.
Any ideas of what's wrong with this formula?
Many thanks.
Tom
(Apologies if this arrives twice. I first sent it from a gmail account.)
Hello All,
Another noob question. Assume I have function foo():
foo <- function(a,b) {
*does some stuff...*
*creates a matrix J
creates a scalar k
*list(J,k)
}
If you run this function, then foo(aye,bee) will return something like this:
[[1]]
[,1] [,2]
[1,] .5 .2
[2,] .4 .3
[[2]]
[,1]
[1,] .8
Let us assume that you want to reference the [1,1]th element of J. If the
function ONLY returned that matrix, then the syntax is the following:
bar <- foo(aye,bee)[1,1]
So far, so good. I cannot figure out how to call that same element when the
function returns two things, though. None of the following work:
baz <- foo(aye,bee)[1,1]
baz <- J.foo(aye,bee)[1,1]
baz <- foo.J(aye,bee)[1,1]
baz <- foo(aye,bee)[1[1,1]]
baz <- foo(aye,bee)[1,1,1]
baz <- foo(aye,bee)[J:1,1]
Does anyone know what the RIGHT syntax is?
Best,
John-Paul
Hi everyone --
I am also looking for a coauthor for Gov 2001. I know some of you from Gov
2000; for everyone else, I am a second-year student in the Law School
(pursuing an academic career in law), and a MSc graduate of the london
school of economics in International Political Economy (IR dept), where I
focused on international trade. I'd be interested in covering IPE topics or
topics touching on issues of law, but I am certainly open to new areas as
well.
best,
John Polley
jpolley at jd10.law.harvard.edu
Hi everyone,
I am a distance education student in this class, way out here in Seattle. Very excited to be a part of the class and I am learning a lot from everyone's questions.
One question which I haven't seen yet, and I didn't see in the section code from last week is how to Print or Save your graphs. I have found the pdf() command, but for some reason I can't get it to work. First I put the command after my graph code, and a .pdf file was created, but 0 kb in size and I couldn't open it. Then I put the pdf() command before my graph code, and I am getting closer. Now a .pdf file is created that is 35kb in size, but I still can't open it. I suspect it has the data in it, but why can't I access it? Is there a command I need to use to close the file in R?
Second question - this wasn't asked in the first lecture (presumably because you all would not have been able to see us raise our hands) but I'm curious - how many E2001 students are currently in the class who are not in the New England area? I know of at least two - myself and one of my coworkers. Anyone else out there in cyberclass? What is your geographic location?
Thanks for the help (and satisfying my curiosity),
Julie Rajaratnam
Julie Knoll Rajaratnam, PhD
Research Scientist
Institute for Health Metrics and Evaluation
Phone: 206-897-2831
Email: jrajarat at u.washington.edu<mailto:jrajarat at u.washington.edu>
Kris --
Many thanks.
Have you or other had experience in R with an error message on running a
function that says
............: multi-argument returns are deprecated
I've written an OLS function that is returning three outputs (coeff,
sigmahatsq, u). Is that illegal in R? Do I need to write three separate
OLS functions: one that returns the Betas, one that returns sigma-hat
squared and one that returns u?
Many thanks.
Best.
Tom
On Tue, Feb 10, 2009 at 10:07 AM, Thomas Sander <tom_sander at harvard.edu>wrote:
> Additional questions to the ones below in my earlier e-mail.
>
> Is there a formula I can use for computing the b intercept under problem
> 2.2 or a R command I can use. I created an OLS function in 2.1 and am using
> that in 2.2, but my OLS function in 2.1 doesn't produce a b intercept, only
> a residual. If you give me the formula for b intercept, I'll code it in R.
>
The intercept isn't really derived from any formula. It is simply another
parameter, just like beta_1 or beta_2. In your code, you cbinded a column
of 1s to your X matrix. The column of 1s corresponds to the beta_0
intercept term. That is, we multiply beta_1 by x_1 and beta_2 by x_2, and
we multiply beta_0 by 1. So the intercept should be the first value in your
beta vector.
>
> And I thought that in the handouts there was instructions about how to name
> parts of a dataset (like naming columns, etc.). I couldn't find this in the
> notes and couldn't find online help in R on this using the '?' command. I
> haven't been able to load the PS1_Data yet, but can you tell me where to
> find out about how to name the parts of the data as I'll need to define this
> as X and Y for my OLS function.
>
If you are working with a dataframe, you can use colnames(data) or
names(data). For a matrix, you can use colnames(matrix). So if I wanted to
name my columns in my dataset, I can do
colnames(my.data) <- c("y", "x1", "x2", "x3")
>
>
> Sorry for the *getting up to speed* questions.
>
> Thanks. Tom
>
> This is coding that I have
>
> #2.1
> OLS<-function(x,y) {
> x<-cbind(matrix(1,nrow(x),1),x) # ADD COLUMN of 1s TO X
> coeff<-solve(t(x)%*%x)%*%(t(x)%*%y) #make coeff equal to X-prime times X
> times x-prime times y
> u<-y-(x%*%coeff) # Create the error term from the residuals of y-Beta times
> x
> sigmahatsq<-(t(u)%*%u)/(nrow(y)-(ncol(x))) #create sigma hat-squared =
> u-prime times u over n-k+1
> # note since I had already added a column of 1s to x I used number of
> columns of x, no x+1
> return(coeff,sigmahatsq,u)
> }
>
> #2.2 run OLS and compute intercept on PS1_Data.RData
> setwd(dir="C:/Documents and Settings/tsander/My
> Documents1/Mdrivebkp/E2001")
> load(PS1_Data.RData)
> data
> head(data)
> tail(data)
> summary(data)
> #name y as the y part of data
> #name x as the explanatory variables part of data
> OLS(x,y)
> # compute intercept NEED TO GET FORMULA
>
> *Thomas Sander*
> Executive Director
> Saguaro Seminar: Civic Engagement in America
> Harvard Kennedy School, Harvard University
> 79 JFK Street, Taubman 364, Cambridge, MA 02138
> T - 617.496-2764 F - 617.495.1589
>
> tom_sander at harvard.edu
> www.hks.harvard.edu/saguaro
>
> new - socialcapitalblog <http://socialcapital.wordpress.com/>
>
> *Please consider the environment before printing this e-mail*
> ----- Forwarded by Thomas Sander/FS/KSG on 02/10/2009 09:57 AM -----
>
>
> *Thomas Sander/FS/KSG*
>
> 02/10/2009 09:19 AM
>
>
> To
>
> plam at fas.harvard.edu
> cc
>
>
> Subject
>
> Couple of other questions Patrick --
>
> A couple of questions:
> 1) I can't seem to figure out how to use the Histogram function. I tried
> ?Hist and didn't really understand the documentation, perhaps because I
> don't have a clear sense of what par(mfrow=c(5,5)) is doing. Is there a
> better place to look to understand examples of how to specify what it is
> doing a histogram for 1.2.2 but I'm clearly missing something
>
> I have
>
> show<-par(mfrow=c(5,5))
> for (i in 1:25) {
> hist(show[i,])
> }
>
> 2) I can't seem to figure out how to load in the PS1_Data.
> I set the wd to be where I keep the data and then loaded the data
>
> setwd(dir="C:/Documents and Settings/tsander/My
> Documents1/MDrivebkp/E2001")
> load(PS1_Data)
>
> I also tried load(PS1_Data.RData)
>
> but in both cases, while it accepts the setwd command, it gives me an error
> on the load command:
> Error in load(PS1_Data.RData) : object "PS1_Data.RData" not found
>
> Any advice?
>
> 3) finally, is there a command to count whether there are odd items in a
> vector? I have kludgy code that sees whether the length of a vector divided
> by 2 and then truncated is not equal to the lenth of a vector divided by 2,
> but there must be a more elegant way to do this, and my code doesn't seem to
> be working.
>
> Many thanks.
>
> Best.
>
> Tom
>
> *Thomas Sander*
> Executive Director
> Saguaro Seminar: Civic Engagement in America
> Harvard Kennedy School, Harvard University
> 79 JFK Street, Taubman 364, Cambridge, MA 02138
> T - 617.496-2764 F - 617.495.1589
>
> tom_sander at harvard.edu
> www.hks.harvard.edu/saguaro
>
> new - socialcapitalblog <http://socialcapital.wordpress.com/>
>
> *Please consider the environment before printing this e-mail*
>
--
Patrick Lam
Department of Government and Institute for Quantitative Social Science,
Harvard University
http://www.people.fas.harvard.edu/~plam<http://www.people.fas.harvard.edu/%7Eplam>
Hi Tom,
I'm forwarding your questions to the list and I encourage everybody to send
questions such as these to the list. More than half the class are new R
users so it would be much better to send to the list than to send to Miya or
I individually. You should all send your questions regardless of how
"basic" you think they are because it is highly likely that there will be
more than a few people with the same questions.
On Tue, Feb 10, 2009 at 9:19 AM, Thomas Sander <tom_sander at harvard.edu>wrote:
> Patrick --
>
> A couple of questions:
> 1) I can't seem to figure out how to use the Histogram function. I tried
> ?Hist and didn't really understand the documentation, perhaps because I
> don't have a clear sense of what par(mfrow=c(5,5)) is doing. Is there a
> better place to look to understand examples of how to specify what it is
> doing a histogram for 1.2.2 but I'm clearly missing something
>
> I have
>
> show<-par(mfrow=c(5,5))
> for (i in 1:25) {
> hist(show[i,])
> }
>
The par(mfrow=c(5,5)) option tells R to plot 25 graphs in one window (5 rows
and 5 columns). It will then put the next 25 plots you specify into the
same window. So if you were trying to plot a histogram of each row of a
matrix called "mat", you would do something like this:
par(mfrow=c(5,5))
for(i in 1:25){
hist(mat[i,]
}
>
> 2) I can't seem to figure out how to load in the PS1_Data.
> I set the wd to be where I keep the data and then loaded the data
>
> setwd(dir="C:/Documents and Settings/tsander/My
> Documents1/MDrivebkp/E2001")
> load(PS1_Data)
>
> I also tried load(PS1_Data.RData)
>
> but in both cases, while it accepts the setwd command, it gives me an error
> on the load command:
> Error in load(PS1_Data.RData) : object "PS1_Data.RData" not found
>
> Any advice?
>
A few people have been having trouble with this. I suspect it is related to
how your computer is reading RData files. I think if you load it directly
from the internet, it should work. Try this:
load(url("
http://isites.harvard.edu/fs/docs/icb.topic542875.files/Problem%20Set%201/P…
"))
You must be connected to the internet to load it, but once you load it, it
is on your R workspace and you do not need to be online. However, if you
close R, you would need to be online to load it again
unless you save your workspace.
>
>
> 3) finally, is there a command to count whether there are odd items in a
> vector? I have kludgy code that sees whether the length of a vector divided
> by 2 and then truncated is not equal to the lenth of a vector divided by 2,
> but there must be a more elegant way to do this, and my code doesn't seem to
> be working.
>
As far as I know, there is no nice prepackaged function to do this.
However, you can use the %% operation, also known as the modulo operation.
The modulo operation gives the remainder when dividing.
So 5 %% 2 gives 1. You can do something like length(vector) %% 2 == 0. If
TRUE, then your vector has an even number. If FALSE, then it has an odd
number.
>
>
> Many thanks.
>
> Best.
>
> Tom
>
> *Thomas Sander*
> Executive Director
> Saguaro Seminar: Civic Engagement in America
> Harvard Kennedy School, Harvard University
> 79 JFK Street, Taubman 364, Cambridge, MA 02138
> T - 617.496-2764 F - 617.495.1589
>
> tom_sander at harvard.edu
> www.hks.harvard.edu/saguaro
>
> new - socialcapitalblog <http://socialcapital.wordpress.com/>
>
> *Please consider the environment before printing this e-mail*
>
--
Patrick Lam
Department of Government and Institute for Quantitative Social Science,
Harvard University
http://www.people.fas.harvard.edu/~plam<http://www.people.fas.harvard.edu/%7Eplam>
Hi All,
I just joined the class on Monday so I apologize for my late start. I'm a
2nd year Public Health grad student. Is anyone still looking for a
co-author? Alternatively, is anyone interested in co-authoring for me on
something in American health policy, such as financing systems, managed
care, or access to health care?
Thanks!
Natasha
6174073651
natasha.khouri at gmail.com
Hi all,
Hope everyone is enjoying the weekend... This is going to sound so much like
a personals add, so my apologies in advance :)
I'm a first year Political Economy and Government PhD student here at
Harvard. I'm a recent graduate from the MPA/ID program at HKS so my general
focus is international development, but looking at it through the lens of
behavioral and experimental economics, comparative politics, and gender,
particularly as related to the Middle East. I'm looking for a positive and
enthusiastic partner/co-author to learn and work with, preferably someone
interested in similar topics, but not necessarily. Please email me directly
if interested: mparyavi at fas.harvard.edu
Thanks so much.
Maliheh
--
Maliheh Paryavi
PhD Candidate
Political Economy & Government
Graduate School of Arts & Sciences
Harvard University