similar to: In optim() function, second parameter in par() missing

Displaying 20 results from an estimated 9000 matches similar to: "In optim() function, second parameter in par() missing"

2009 Sep 08
1
optim() argument scoping: passing parameter values into user's subfunction
Dear useRs, I have a complicated function to be optimized with optim(), and whose parameters are passed to another function within its evaluation. This function allows for the parameters to enter as arguments to various probability distribution functions. However, I am violating some scoping convention, as somewhere within the hierarchy of calls a variable is not visible. I will give a
2009 Feb 12
1
Optim
Dear R user I follow the steps defined in Modern applied statistics page(453) to use optim. However, when I run the following code the parameters seems way off and the third parameter(p3) stayed as the initial value. below is the code: ## data da=c(418,401,416,360,411,425,537,379,484,388,486,380,394,363,405,383,392,363,398,526) ### initial values pars=c(392.25, 507.25, 0.80)
2011 May 30
1
Error in minimizing an integrand using optim
Hi, Am not sure if my code itself is correct. Here's what am trying to do: Minimize integration of a function of gaussian distributed variable 'x' over the interval qnorm(0.999) to Inf by changing value of parameter 'mu'. mu is the shift in mean of 'x'. Code: # x follows gaussian distribution # fx2 to be minimized by changing values of mu # integration to be done over
2007 Apr 18
3
Problems in programming a simple likelihood
As part of carrying out a complicated maximum likelihood estimation, I am trying to learn to program likelihoods in R. I started with a simple probit model but am unable to get the code to work. Any help or suggestions are most welcome. I give my code below: ************************************ mlogl <- function(mu, y, X) { n <- nrow(X) zeta <- X%*%mu llik <- 0 for (i in 1:n) { if
2009 Aug 07
1
Gauss-Laguerre using statmod
I believe this may be more related to analysis than it is to R, per se. Suppose I have the following function that I wish to integrate: ff <- function(x) pnorm((x - m)/sigma) * dnorm(x, observed, sigma) Then, given the parameters: mu <- 300 sigma <- 50 m <- 250 target <- 200 sigma_i <- 50 I can use the function integrate as: > integrate(ff, lower= -Inf, upper=target)
2011 Jul 04
3
loop in optim
Hi May you help me correct my loop function. I want optim to estimates al_j; au_j; sigma_j; b_j by looking at 0 to 20, 21 to 40, 41 to 60 data points. The final result should have 4 columns of each of the estimates AND 4 rows of each of 0 to 20, 21 to 40, 41 to 60. ###MY code is n=20 runs=4 out=matrix(0,nrow=runs) llik = function(x) { al_j=x[1]; au_j=x[2]; sigma_j=x[3]; b_j=x[4]
2004 Sep 21
1
Problems with boot and optim
I am trying to bootstrap the parameters for a model that is estimated through the optim() function and find that when I make the call to boot, it runs but returns the exact same estimate for all of the bootstrap estimates. I managed to replicate the same problem using a glm() model but was able to fix it when I made a call to the variables as data frame by their exact names. But no matter how I
2003 Sep 08
1
Probit and optim in R
I have had some weird results using the optim() function. I wrote a probit likelihood and wanted to run it with optim() with simulated data. I did not include a gradient at first and found that optim() would not even iterate using BFGS and would only occasionally work using SANN. I programmed in the gradient and it iterates fine but the estimates it returns are wrong. The simulated data work
2004 Jul 08
1
(PR#7070)
> version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 7.1 year 2003 month 06 day 16 language R Bug: integrate(f,lower,upper,extra_args) where f <- function(x,extra_args) { body } integrate doesn't pass the extra arguments when calling f. As a first check of this finding I integrated dnorm from
2007 Oct 16
1
Calculating confidence in an estimate including number of trials?
[Yes, this is related to a homework problem, but is not the problems itself.] In my mathematical statistics class, we've just learned about properties of estimators, and I can now solve manually problems like this: A sample of size n = 16 is drawn from a normal distribution where sigma = 10 but mu is unknown. If mu = 20, what is the probability that the estimator mu hat = Y bar will lie
2004 Aug 06
3
Bug in qnorm or pnorm?
I found the following strange behavior using qnorm() and pnorm(): > x<-8.21;x-qnorm(pnorm(x)) [1] 0.0004638484 > x<-8.22;x-qnorm(pnorm(x)) [1] 0.01046385 > x<-8.23;x-qnorm(pnorm(x)) [1] 0.02046385 > x<-8.24;x-qnorm(pnorm(x)) [1] 0.03046385 > x<-8.25;x-qnorm(pnorm(x)) [1] 0.04046385 > x<-8.26;x-qnorm(pnorm(x)) [1] 0.05046385 > x<-8.27;x-qnorm(pnorm(x))
2011 Jul 03
3
Hint improve my code
Hi I have developed the code below. I am worried that the parameters I want to be estimated are "not being found" when I ran my code. Is there a way I can code them so that R recognize that they should be estimated. This is the error I am getting. > out1=optim(llik,par=start.par) Error in pnorm(au_j, mean = b_j * R_m, sd = sigma_j) : object 'au_j' not found #Yet
2013 Apr 12
1
A strange behaviour in the graphical function "curve"
I thought the curve function was a very flexible way to draw functions. So I could plot funtions like the following: # I created a function to produce functions, for instance: fp <- function(m,b) function(x) sin(x) + m*x + b # So I can produce a function like this ff <- fp(-0.08, 0.2) ff(1.5) # Is the same as executing sin(1.5) - 0.08*1.5 + 0.2 # Let's plot this
2011 Feb 21
1
question about solving equation using bisection method
Hi all, I have the following two function f1 and f2. f1 <- function(lambda,z,p1){ lambda*(p1*exp(-3*z-9/2)+(0.2-p1)*exp(4*z-8))-(1-lambda)*0.8} f2 <- function(p1,cl, cu){ 0.8*(pnorm(cl)+(1-pnorm(cu)))/(0.8*(pnorm(cl)+(1-pnorm(cu)))+p1*(pnorm(cl+3)+(1-pnorm(cu+3)))+(0.2-p1)*(pnorm(cl-4)+(1-pnorm(cu-4))))}-0.05 First fix p1 to be 0.15. (i) choose a lambda value, say lamda=0.6, (ii)
2012 Nov 12
1
Invalid 'times' argument three-category ordered probit with maximum likelihood
Hello, First time poster here so let me know if you need any more information. I am trying to run an ordered probit with maximum likelihood model in R with a very simple model (model <- econ3 ~ partyid). Everything looks ok until i try to run the optim() command and that's when I get " Error in rep(1, nrow(x)) : invalid 'times' argument". I had to adapt the code from a 4
2010 Jul 06
1
plotmath vector problem; full program enclosed
Here's another example of my plotmath whipping boy, the Normal distribution. A colleague asks for a Normal plotted above a series of axes that represent various other distributions (T, etc). I want to use vectors of equations in plotmath to do this, but have run into trouble. Now I've isolated the problem down to a relatively small piece of working example code (below). If you would
2008 Jan 24
2
testing coeficients of glm
Dear list, i'm trying to test if a linear combination of coefficients of glm is equal to 0. For example : class 'cl' has 3 levels (1,2,3) and 'y' is a response variable. We want to test H0: mu1 + mu2 - mu3 =0 where mu1,mu2, and mu3 are the means for each level. for me, the question is how to get the covariance matrix of the estimated parameters from glm. but perhaps there
2009 Jul 17
2
how to evaluate character vector within pnorm()
Hi, I'm trying to evaluate a character vector within pnorm. I have a vector with values and names x = c(2,3) names(x) = c("mean", "sd") so that i tried the following temp = paste(names(x), x, sep = "=") #gives #> temp #[1] "mean=2" "sd=3" #Problem is that both values 2 and 3 are taken as values for the mean argument in pnorm pnorm(0,
2004 Jun 16
2
erf function documentation
Hi all. I may be wrong, (and often am), but in trying to determine how to calculate the erf function, the documentation for 'pnorm' states: ## if you want the so-called 'error function' erf <- function(x) 2 * pnorm(x * sqrt(2)) - 1 ## and the so-called 'complementary error function' erfc <- function(x) 2 * pnorm(x * sqrt(2), lower=FALSE) Should, instead, it read:
2011 Sep 11
3
(no subject)
Dear all, Can anyone take a look at my program below? There are two functions: f1 (lambda,z,p1) and f2(p1,cl, cu). I fixed p1=0.15 for both functions. For any fixed value of lambda (between 0.01 and 0.99), I solve f1(p1=0.15, lambda=lambda, z)=0 for the corresponding cl and cu values. Then I plug the calculated cl and cu back into the function f2. Eventually, I want to find the lambda value