[R] Probit regression with limited parameter space
Dear R helpers, I need to estimate a probit model with box constraints placed on several of the model parameters. I have the following two questions: 1) How are the standard errors calclulated in glm (family=binomial(link=probit)? I ran a typical probit model using the glm probit link and the nlminb function with my own coding of the loglikehood, separately. As nlminb does not produce the hessian matrix, I used hessian (numDeriv) to calculate it. However, the standard errors calculated using hessian function are quite different from the ones generated by the glm function, although the parameter estimates are very close. I was wondering what makes this difference in the estmation of standard errors and how this computation is carried out in glm. 2) Does any one know how to estimate a constrained probit model in R (to be specific, I need to restrain the range of three parameters to [-1,1])? Among the optimation functions, so far nlminb and spg work for my problem, but neither produces a hessian matrix. As I mentioned above, if I use hessian funciton and calculate standard errors manually, the standard errors seem not right. Many thanks in advance for your kind help. Maomao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to draw a map of Europe?
Hi R users, I need to draw a map of select European countries with country names shown on the map. Does anyone know how to do this in R? Also, is it possible to draw a historical map of European countries using R? Thanks a lot for your help. Maomao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] if statement and truncated distribution
Hi R helpers, I am trying to use the if statement to generate a truncated random variable as follows: if (y[i]==0) { v[i] ~ rnorm(1,0,1) | (-inf ,0) } if (y[i]==1) { v[i] ~ rnorm(1,0,1) | (0, inf) } I guess I cannot use | ( , ) to restrict the range of a variable in R. Could you let me know how to write the code correctly in R? Many thanks for your help. Maomao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem using BRugs
Hi R users, I am trying to call openbugs from R. And I got the following error message: ~ model is syntactically correct expected the collection operator c error pos 8 (error on line 1) variable ww is not defined in model or in data set [1] C:\\DOCUME~1\\maomao\\LOCALS~1\\Temp\\RtmpqJk9R3/inits1.txt Initializing chain 1: model must be compiled before initial values loaded model must be initialized before updating model must be initialized before DIC an be monitored Error in samplesSet(parametersToSave) : model must be initialized before monitors used ~~ I did define variable ww in my data and model (they are listed below). I am not sure if this is due to some errors in my code (please see below) or because openbugs cannot handle the model I am using. In my model, y[i] also depends on all other y[j]s. Could you help me figure out the problem and hopefully get the code to work? Many thanks for your help. --- Maomao ~~ data-list(y,cap2,pol2,cap1,pol1,g,wo,wd,ww,mu,tau) inits-function() {list(beta=beta0, rho_o=rho_o_0, rho_d=rho_d_0, rho_w=rho_w_0)} parameters-c(beta, rho_o, rho_d, rho_w) probit.sim-BRugsFit(data,inits,parameters,modelFile=spatial.openbugs.txt,numChains=1,nIter=2000) # my model model { for (i in 1:676) { y[i] ~ dbern(p[i]) wwy[i]- inprod(ww[i, 1:676] , y[]) woy[i]- inprod(wo[i, 1:676] , y[]) wdy[i]- inprod(wd[i, 1:676] , y[]) probit(p[i])- rho_o * woy[i] + rho_d * wdy[i] + rho_w * wwy[i] + beta[1] + beta[2] * cap2[i] + beta[3] * pol2[i] + beta[4] * cap1[i] + beta[5] * pol1[i] + beta[6] * g[i]+ e[i] } # Priors for (j in 1:6) { beta[1:6] ~ dmnorm(mu[1:6], tau[1:6, 1:6]) } rho_o ~ dunif(-1,1) rho_d ~ dunif(-1,1) rho_w ~ dunif(-1,1) for (i in 1:676) { e[i] ~ dnorm(0, 1) } } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Place constrictions on parameters when using Optim and MaxLik
Hi R users, I am trying to restrct the range of two of the parameters in a maximization problem. Both parameters should be between -1 and 1. As far as I know, if I choose the estimation method =L-BFGS-B under Optim, I can restrict the parameter space. However, the L-BFGS-B always require finite values of the loglik function and cannot get around of the problem if an infinite value occurs. Does anyone know how to restrict parameters with other algorithms such as BFGS or SANN under the Optim function? Also can I restrict parameters to be within a certain range when using MaxLik? Thanks so much for your help. Maomao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Can I monitor the iterative/convergence process while using Optim or MaxLik?
Hi R-helpers, Is it possible that I have the estimates from each step/iteration shown on the computer screen in order to monitor the process while I am using Optim or MaxLik? Thanks for your help. Maomao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How can I fixe convergence=1 in optim
Hi R users, I am using the optim funciton to maximize a log likelihood function. My code is as follows: p-optim(c(-0.2392925,0.4653128,-0.8332286, 0.0657, -0.0031, -0.00245, 3.366, 0.5885, -0.8, 0.0786,-0.00292,-0.00081, 3.266, -0.3632, -0.49,0.1856, 0.00394, -0.00193, -0.889, 0.5379, -0.63, 0.213, 0.00338, -0.00026, -0.8912, -0.3023, -0.56), f, method =BFGS, hessian =TRUE, y=y,X=X,W=W) After I ran the code, I got the following results: p $par [1] 2.235834e-02 1.282826e-01 -3.786014e-01 7.422526e-02 3.037931e-02 -2.570156e-03 3.365872e+00 2.618893e-01 -1.987859e-06 [10] 7.970083e-02 2.878574e-03 -1.391019e-03 3.265966e+00 -4.153697e-01 -3.185684e-03 1.833200e-01 -7.247683e-03 -3.156813e-03 [19] -8.889219e-01 6.208612e-01 2.678643e-04 2.183787e-01 2.715062e-02 2.943905e-04 -8.913260e-01 -5.100482e-01 -3.477559e-04 $value [1] -932.1423 $counts function gradient 1439 100 $convergence [1] 1 $message NULL $hessian ( I omitted the approximation results for the hessian here to save space) ~~ The error code 1 for convergence shown above means that the iteration limit maxit had been reached. How can I fix this problem and achieve convergence for my optimization problem? Can I increase the number of maxit so that convergence might occur? Thanks for your help. If more information is needed, please let me know. Maomao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] What does this warning message (from optim function) mean?
Hi R users, I am trying to use the optim function to maximize a likelihood funciton, and I got the following warning messages. Could anyone explain to me what messege 31 means exactly? Is it a cause for concern? Since the value of convergence turns out to be zero, it means that the converging is successful, right? So can I assume that the parameter estimates generated thereafter are reliable MLE estimates? Thanks a lot for your help. Maomao p-optim(c(0,0,0), f, method =BFGS, hessian =T, y=y,X=X,W=W) There were 31 warnings (use warnings() to see them) warnings() Warning messages: 1: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 2: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 3: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 4: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 5: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 6: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 7: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 8: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 9: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 10: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 11: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 12: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 13: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 14: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 15: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 16: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 17: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 18: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 19: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 20: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 21: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 22: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 23: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 24: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 25: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 26: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 27: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 28: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 29: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 30: In log(det(I_N - pd * wd - po * wo - pw * ww)) : NaNs produced 31: In if (hessian) { ... : the condition has length 1 and only the first element will be used p$counts function gradient 148 17 p$convergence [1] 0 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.