Hi all,
Can anyone explain to me how to use optim() for two dimension function?
Here is my code:
x_y_density<-function(x,y){exp(-((x-2)^2+(y-1)^2))}
...
par=c(0,0.05)
optim(par, x_y_density, method="BFGS")
I get the following error message and don't know how to fix it:
> par=c(0,0.05)
> optim(par, x_y_density(par), method="BFGS")
Error in x_y_density(par) : element 1 is empty;
the part of the args list of '-' being evaluated was:
(y, 1)
Thanks!
Sincerely,
Olena Ageyeva
_________________________________________________________________
Windows Live?: Discover 10 secrets about the new Windows Live.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!5…
Hi guys,
I've implemented a code for method of bisection, but when I tried it on the intervals [-3, -.5], and [-.5,1], my algorithm does not converge with a tolerance rate of 0.001. I think the reason why this is happening is because in my base case, I always check the condition:
if(f(x_m) == 0)
However, I noticed that in the case of the interval [-3, -.5], the f(x_m) only gets really really close to 0, but never exactly equals 0.
My question is that should I implement some sort of round-off condition, or is this is known convergence problem with the method of bisection?
By round-off condition, I mean that if f(x_m) gets to be around 0.0001, then I'd tell the program that this is close enough to zero and return the x_m value.
Thanks,
Clarence
Hi everyone -
I'm having last-minute insecurities: In problem 4 part a), we weren't to
fully derive the expected value and variance of the function, were we? It's
an easy enough exercise on paper, but LaTeX and I still have a bit of a
strained relationship this early in the semester......
However, I don't want to come off lazy, jumping from noting the integral
form into using the results without deriving them "by hand" on a word
processor.....
Any insight into expectations?
Thanks!
Rachel
--
"We have always known that heedless self-interest was bad morals; we know
now that it is bad economics." -FDR
Dear Patrick and Miya
I am trying to download Latex but am failing to get the link. I managed to
this easily
for R. I need this for mathematical expressions and assignments
regards
Stanley Chitekwe (Bsc Hon, MMed Sci)
Nutrition Manager
Health & Nutrition Section
UNICEF Lilongwe
P.O Box 30375
Lilongwe 3, Malawi
Tel: 00265-1-770781
Mobile: 00265-9964548
Hi everyone,
Rather scarily, I'm still looking for a co-author. I'm a Masters student at MIT
and would ideally like to work on something in the field of public opinion. I
have a particular paper in mind for replication that explores the relationship
between public perceptions of the president's economic management and the
content of the news media, but obviously at this rather late stage I'm very
willing to be flexible.
If this sounds something you might be interested in or have other ideas in a
similar field, please get in touch.
All the best,
Matt
Hi Folks,
I realize that we went through a lot of the section material pretty quickly
tonight (esp. for those in the first section). In case you want
clarification on anything that was covered, I will be holding office hours
tomorrow from 2:30 till 4:30 in the CGIS computer lab.
Thanks,
Miya
--
Miya Woolfalk
Ph.D. Student
Harvard University
Government and Social Policy
Thank your for your help. The examples were extremely helpful!
Can anyone explain me how rexp(n, rate) works? Is rate equal to lambda? Is that simulation for the function: lambda*e^(-lambda*x)?
Also, do I use a right formula for variance? I get an error when I try to Vectorize() it. Without vectorizing everything works fine.
Var<-function(x,lambda){E((x-E(x,lambda))^2,lambda)}
> Var.x<-integrate(Vectorize(Var),lambda,lower=0, upper=Inf)
Error in eval(expr, envir, enclos) :
..1 used in an incorrect context, no ... to look in
Sincerely,
Olena Ageyeva
_________________________________________________________________
Get more out of the Web. Learn 10 hidden secrets of Windows Live.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!5…
Hi All,
It's flattering to write in pset 2, problem 4 that we might "forget" to use
Vectorize(), when in truth I for one cannot figure out why we would need it
in the first place. The command's documentation is not, frankly, the most
informative I've ever read. Can someone in the know clue me in as to its use
here?
Thanks,
John-Paul Ferguson
PhD Candidate, Economic Sociology
MIT Sloan School of Management
50 Memorial Drive, E52-533
Cambridge, MA 02142
617.253.3940 (w)
617.549.8482 (c)
Hello, All.
Does anyone know how to exclude one item from a vector? I have a vector (a,b,c,d,e) and I need just (b,c,d,e).
Sincerely,
Olena Ageyeva
_________________________________________________________________
See how Windows Mobile brings your life together?at home, work, or on the go.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/
Hi all,
When it is asked in question 3 of the problem set that the function should have the months I am sampling from as inputs, can I assume that this will be the whole range of months (from 1 to 12) or any range of months? (like for example May, June, July , so that my input for months would be c(5,6,7)).
I am writing my function under the assumption that we sample from all available months and not only a specific range, but I wanted to make sure that is is the correct assumption.
Thanks,
Sanjay
________________________________
From: gov2001-l-bounces at lists.fas.harvard.edu [gov2001-l-bounces at lists.fas.harvard.edu] On Behalf Of Patrick Lam [plam at fas.harvard.edu]
Sent: Monday, February 16, 2009 10:06 PM
To: gov2001-l at lists.fas.harvard.edu
Subject: Re: [gov2001-l] R command for tabulating frequency
I'm not aware of a mode function, although it doesn't mean it doesn't exist.
good catch on the second point. you're absolutely right! for the purposes of this problem though, ignore the fact that such an issue exists.
On Mon, Feb 16, 2009 at 8:35 PM, Lai, Ronald <rolai at hbs.edu<mailto:rolai at hbs.edu>> wrote:
Is there simply a "Mode" function in R?
For 4d.
What is the range? Initially, I thought it would be 0 -> Inf
Since ln(0) = error and ln(Inf) = Inf.. this seems like an issue!
From: gov2001-l-bounces at lists.fas.harvard.edu<mailto:gov2001-l-bounces at lists.fas.harvard.edu> [mailto:gov2001-l-bounces at lists.fas.harvard.edu<mailto:gov2001-l-bounces at lists.fas.harvard.edu>] On Behalf Of Johnathan Boysielal
Sent: Monday, February 16, 2009 8:31 PM
To: gov2001-l at lists.fas.harvard.edu<mailto:gov2001-l at lists.fas.harvard.edu>
Subject: Re: [gov2001-l] R command for tabulating frequency
If you have a vector like n <- c(1, 2, 3, 4, 1, 2, 3, 2, 1, 2)
q <- table(n);q # will generate a frequency table
n
1 2 3 4
3 4 2 1
You can also apply operations like max() or mean() to q, and use it to subset the original vector. E.g.:
unique(n[q>2]) #will list all the elements of n appearing more than 2 times
[1] 1 2
Hope that helps,
John
On Mon, Feb 16, 2009 at 6:39 PM, Rachel West <rwest817 at gmail.com<mailto:rwest817 at gmail.com>> wrote:
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
_______________________________________________
gov2001-l mailing list
gov2001-l at lists.fas.harvard.edu<mailto:gov2001-l at lists.fas.harvard.edu>
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
_______________________________________________
gov2001-l mailing list
gov2001-l at lists.fas.harvard.edu<mailto:gov2001-l at lists.fas.harvard.edu>
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
--
Patrick Lam
Department of Government and Institute for Quantitative Social Science, Harvard University
http://www.people.fas.harvard.edu/~plam