Also, a useful property of matrix algebra is that, if A is a n x 1 matrix
(or row vector of length n), then its transpose is a 1 x n matrix (or column
vector of length one).
Perform matrix algebra one way and you get a n x n square matrix, and
another way you get a 1 x 1 matrix (i.e. single value).
The value of the 1 x 1 matrix is the squared sum of the values of the vector
elements.
For example:
A <- c(1,2,3)
A
[1] 1 2 3 # row vector
A.trans <- t(A)
A.trans
[,1] [,2] [,3]
[1,] 1 2 3 # column vector
A %*% A.trans
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 2 4 6
[3,] 3 6 9
A.trans %*% A
[,1]
[1,] 14 # i.e. 1^2 + 2^2 + 3^2
-----Original Message-----
From: gov2001-l-bounces at
lists.fas.harvard.edu
[mailto:gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of mastrangelo,
paolo
Sent: 14 February 2007 05:57
To: gov2001-l at
lists.fas.harvard.edu
Subject: Re: [gov2001-l] writing function for A
Hi shauna,
This will hopefully help without giving you "the answer" :
In the first lecture remember that Gary wrote the standard linear regression
model (in matrix notation) as Y = xB + e. Y and x are the dependent and
expalantory variables, while B (beta) and e (error term) are OLS paramaters
that we're being asked to estimate.
So in your function you need to have computations for these two paramaters,
and in addition one for sigma^2 (the variance).
You might want to look online to find out how the paramaters are defined in
matrix notation (maybe the John Fox book that was used for gov-2000). Gary
gave us the formula for beta in the first lecture as a "litmus test" for our
knowledge, and remember that it was the inverse of (X'X) times (X'Y).
The matrix hand out shows how you can do inverses and transponses: so it's a
question of coming up with a clever way to use (solve) (t) and (%*%) in the
same line using X and Y...
And the function is general so once you specify the inputs you can use them
for all of the paramater computations in the function...
Hope this helps!
Paolo
-----Original Message-----
From: gov2001-l-bounces at
lists.fas.harvard.edu on behalf of Shauna Lani
Shames
Sent: Wed 2/14/2007 12:08 AM
To: gov2001-l at
lists.fas.harvard.edu
Subject: [gov2001-l] writing function for A
Hiya folks,
I'm having trouble writing the function for part A of the "for credit"
section of the prob set. I can do all the "remedial" R stuff, and using
lm() I can do parts B and C of the "for credit," but I'm not solid enough
on
matrix algebra to apply it to finding OLS coefficients and the SE's.
I've read and understood the "matrix algebra" review sheet posted, as well
as the chapters in the King text, but neither seems helpful for writing this
function. I guess I just don't quite know how to start with the function,
since I'm not familiar enough with the process and equations needed to find
OLS coefficients to begin with (I've just always used lm!). If it's not a
violation of posting answers to the list, can someone give me some useful
hints about how to do this?
-- shauna
**********************
Shauna L. Shames
Ph.D. Candidate
American Government
Harvard University
shames at
fas.harvard.edu
_______________________________________________
gov2001-l mailing list
gov2001-l at
lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.37/682 - Release Date: 12/02/2007
13:23
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.37/682 - Release Date: 12/02/2007
13:23