Very elementary question, I'm sure, but I'm new to R :
What is a command in R which would return the frequency elements in a
vector, and could be applied with "any" to recognize when a threshold
frequency has been achieved?
For example, if I have a vector
n <- [1, 2, 3, 4, 1, 2, 3, 2, 1, 2],
is there a command that will output the number of instances of the most
frequent element (i.e, "2" is repeated 4 times), or something similarly
useful?
Thanks,
Rachel
Hi All,
PS 1 is graded.
For those who handed in a hard copy of the problem set: Your write up (with
grade and brief comments) will be returned to you during section on
Thursday.
For those who submitted the problem set by email because the dropbox was
unavailable to them: Your grade (with brief comments) will be emailed to
you. Also, *please square away your registration as soon as possible!
Check to see if you now have access to the ps dropbox. If not, contact the
registrar and make sure they have the required paperwork and that everything
is being processed. Getting you registered is important for a handful of
reasons including signing you up for access to lecture and section videos
(remember: access will be restricted to non-extension students after the
shopping period is over).*
For those who only submitted their problem set to the dropbox (i.e.g did not
hand in a hard copy of the problem set or submit the problem set by email):
Your grade (with brief comments) is posted as a "comment" under the uploaded
file for your write up in the dropbox.
Thanks,
Miya
--
Miya Woolfalk
Ph.D. Student
Harvard University
Government and Social Policy
Hi all,
The wording on questions like this always confuses me. We are asked, "If a
researcher interviews 5 separate individuals [out of the 25 in the village]
randomly selected with equal probability, what is the probability that she
will not talk to a single supporter of the government?"
I seems like you could treat this two ways:
1. What is the probability of getting 0 successes in 5 draws from a
population of arbitrary size but fixed probability of success? If you did it
this way, you'd use the binomial distribution with n = 5, k = 0 and pi =
6/25.
2. What is the probability of getting 5 sequential failures in 5 draws from
a population of 25 where there are 6 potential "successes"? If you did it
this way, you'd use the hypergeometric distribution with k = 0, N = 25, m =
6 and n = 5.
The second approach feels more natural, but is it?
John-Paul
Hi Folks,
I encourage you all to take a look at the solution set (especially the R
code) before getting too far into working on ps2. Although many of you were
able to successfully complete ps1, there are more efficient ways to answer
many of the questions in ps1 (e.g. using apply() rather than for() ). Neat
and concise code is generally always better.
Miya
--
Miya Woolfalk
Ph.D. Student
Harvard University
Government and Social Policy
Hello,
*EVERYONE:*
When you *submit your problem sets to the problem set drop box*, we want *two
files*:
(1) A *write up *of your homework in *pdf format*: This write up should
contain your *answers to the problem set questions* (e.g. tables, figures,
explanations, etc). It should also contain *all code necessary to complete
each problem*. The relevant code should appear in the corresponding section
of your write up (e.g. the code to answer question 2.1 should appear
directly under your answer to question 2.1). I have updated the write up
for the solutions to problem set 1. Please have a look to make sure that
your write up for each future problem set follows this format.
(2) A *txt or r file *with all of your *R code:* This file should contain *all
of the commands necessary to answer the questions* in the problem set. It
should be able to reproduce all of your answers in the problem set write up
and run without errors. We recommend that you clear the workspace and
re-run all of your code before submitting your problem set. This will make
sure that everything runs without errors. This file *should be written
using an editor* (the R editor or otherwise) and should not be produced by
copying and pasting the R console into a txt file.
*NON-EXTENSION STUDENTS:*
When you *submit the hard copy of your problem set in section*, we want *one
document*, your problem set *write up*.
Thanks,
Miya
--
Miya Woolfalk
Ph.D. Student
Harvard University
Government and Social Policy
Hi all,
Two mistakes I made on my slides for section.
1. Jensen's inequality is E(g(X)) >= g(E(X)) for convex functions only.
The inequality switches signs for concave functions.
2. The coding error in my simulation problem is that I neglected to account
for the fact that I took out one marble in the first urn after the first
draw. When I do my final draw, the urn has one more marble in it than it
should. Think about how you would correct that.
--
Patrick Lam
Department of Government and Institute for Quantitative Social Science,
Harvard University
http://www.people.fas.harvard.edu/~plam
Hi Folks,
Please be sure to submit your problem set writeup as a pdf document. The R
code can either be in .r or .txt format.
Students who already uploaded their write-up and R code but did so in a
different format: Please delete the existing files and upload your homework
in the correct format.
I realize that this was not stated in the homework policy document and
apologize for any inconvenience. We are making this change to the policy
mainly because older versions of Word can not always read documents produced
using newer versions of Word.
Thanks,
Miya Woolfalk
--
Miya Woolfalk
Ph.D. Student
Harvard University
Government and Social Policy
Hi all,
Don't forget, your problem sets are due by tomorrow at 7 into your
respective dropboxes. Local students, please bring a hardcopy of your
writeup to whichever section you attend.
The new problem set will be released tomorrow night at 9 pm.
--
Patrick Lam
Department of Government and Institute for Quantitative Social Science,
Harvard University
http://www.people.fas.harvard.edu/~plam
It's a steep learning curve this week between R and LaTeX . I successfully
downloaded LaTeX through the ProTexnic Center. And tried using it.
If people have used LaTeX before, is there an easy way to
1) preview what you are doing (without all the formating codes)
2) how to print from LaTeX into a PDF without all the formatting codes? I
think if I could figure out #1 I could figure out #2, but if I try to do a
PDF now it keeps all the formatting codes in.
3) create a table. When I do Insert - Table I get a lot of code like
\begin \table (etc.) but I don't see any choices other than 1
or 2 columns and nothing that enables me to see the table as I'm creating
it.
Any one out there an experienced LaTeX user?
Many thanks.
Best.
Tom
Hi All,
I wanted to let you all know about a great resource in the Government
department. Pedram Safari (safari at fas.harvard.edu) is a math preceptor and
he is available Monday, Wednesday and Friday from 11am-12pm in CGIS S310 to
answer any questions you may have about math (e.g. integration, derivatives,
optimization) and probability theory (e.g. probability distributions,
conditional probability, MCMC methods). He is happy help students gain a
better understanding of the math and theory underlying many of the topics we
cover in Gov 2001. So, you should all feel free to stop by his office
during those hours.
Best,
Miya
--
Miya Woolfalk
Ph.D. Student
Harvard University
Government and Social Policy