[R] mle from stats4
I am using mle as a wrapper from optim( ). How would I extract the convergence code, to know that optim( ) converged properly? Thanks, Stephen Collins, MPP | Analyst Global Strategy | Aon Benfield [[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] Using linear formula inside MLE
Say I have a formula Y ~ 1 + X, where X is a categorical variable. A previous thread showed how to evaluate this model using the mle package from stats4 (see below). But, the user had to create the data matrix, X, including the column of one's for the regression constant. Is there a way to nest the linear formula in the code below, so the data matrix doesn't explicitly have to be created by the user? Y - c(0,0,1,0,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,0,1) X - cbind(matrix(1,21,1),matrix(c(-48.5,24.4,82.8,-24.6,-31.6,91.0,52.1,-87.7,-17.0,-51.5, -90.7,65.5,-44.0,-7.0,51.6,32.4,-61.8,34.0,27.9,-72.9,49.9), 21,1)) log.lo.like - function(beta,Y,X) { Fbetax - 1/(1+exp(-beta%*%t(X))) loglbeta - -log(prod(Fbetax^Y*(1-Fbetax)^(1-Y))) } #Using MLE# ll - eval(function(beta0=0,beta1=0) log.lo.like (c(beta0,beta1),Y,X), list(X=X,Y=Y)) summary(mle(ll)) Comparison using glm# glm(Y~X-1,family=binomial) Thanks, Stephen Collins, MPP | Analyst Global Strategy | Aon Benfield [[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] optim() question
I've seen with other software the capability for the optimizer to switch algorithms if it is not making progress between iterations. Is this capability available in optim()? Thanks, Stephen Collins, MPP | Analyst Health Benefits | Aon Consulting [[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] mle() question
Is there a way to code the mle() function in library stats4 such that it switches optimizing methods midstream (i.e. BFGS to Newton and back to BFGS, etc.)? Thanks, Stephen Collins, MPP | Analyst Health Benefits | Aon Consulting [[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] loglik and arima()
All - I am evaluating an arima(2,1,3) and arima(3,1,3) and notice the log-likelihood of the restricted model is higher than the log-likelihood of the unrestricted. Since these are nested models, I thought the unrestricted model would have a log-likelihood at least as large as that of the restricted model. Am I interpreting the loglik output incorrectly? Regards, Stephen Collins, MPP | Analyst Health Benefits | Aon Consulting 200 East Randolph, Suite 900, Chicago, IL Tel: 312-381-2578 | Fax: 312-381-0136 Email: stephen_coll...@aon.com Aon Consulting selected by the readers of Business Insurance as the âBest Employee Benefit Consulting Firmâ in 2006, 2007, and 2008 NOTE: The information contained in this transmission, including any attachment(s) is only for the use of the intended individual(s) or entity, and may contain information that is privileged and confidential. If the reader of this message is not an intended recipient, you are hereby notified that any dissemination, distribution, disclosure, or copying of this information is unauthorized and strictly prohibited. If you have received this communication in error, please contact the sender immediately by reply email and destroy all copies of the original message. [[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] Categorical Variables and glm()
When including categorical variables in a regression, the default in R is to set the first level as the base. Is there an option to specify a different level as the base? Regards, Stephen Collins, MPP | Analyst Health Benefits | Aon Consulting [[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] Viewing code
How do you view the code for a built-in R command (i.e., if I want to see what R is doing when I run a glm() statement)? Regards, Stephen [[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 fast of a desktop can I buy?
I currently run simulations on an IBM x31 Thinkpad (laptop), with an Intel Pentium M, 1.3GHz processor. I am planning to buy a desktop to help speed up my work, but I am wondering if R is compatible with some of the newer technology that has come to market (i.e., Intel Core 2 Duo, Quad Core processors, 64-bit operating systems). Does anyone know the threshold or limit on R's capabilities, where buying more computer ceases to impact the speed at which R executes its task at hand? I need to know what type of processor, how much memory, cache, etc., I should be looking for in a desktop. Regards, Stephen Collins, MPP | Analyst Health Benefits | Aon Consulting 200 East Randolph, Suite 900, Chicago, IL Tel: 312-381-2578 | Fax: 312-381-0136 Email: [EMAIL PROTECTED] Aon Consulting selected by the readers of Business Insurance as the âBest Employee Benefit Consulting Firmâ in 2006, 2007, and 2008 NOTE: The information contained in this transmission, including any attachment(s) is only for the use of the intended individual(s) or entity, and may contain information that is privileged and confidential. If the reader of this message is not an intended recipient, you are hereby notified that any dissemination, distribution, disclosure, or copying of this information is unauthorized and strictly prohibited. If you have received this communication in error, please contact the sender immediately by reply email and destroy all copies of the original message. [[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] Vectorizing sample()
I am simulating sickness among a group of families. Part of the task is to randomly draw who in the family will be sick, randomly drawing from family ID's where Dad =1, Mom = 2, Kid1 = 3, Kid2 = 4., etc. My census of Dads is of the form shown below. Dad_ID Spouse (Y=1;N=0)#Kids #People_Becoming_Sick 1 1 0 1 2 0 2 2 3 1 0 2 4 1 3 3 ... The end output needed is if 3 people in a family are to be sick, was it the dad and two kids, with random family ID's = {1,3,4}, or the mom, dad, and one kid, with random family ID's = {2,1,4}, etc.. The complication is that length of the family ID's to choose from and the associated sampling probabilities -- changes with each family. I could loop through the Dads, from i in 1:nrow(census), but is there a way I could vectorize sample() to get at the same objective? My attempts to use the apply-based functions have dead ended. Other ideas to vectorize this problem are warmly welcomed. Regards, Stephen Collins, MPP | Analyst Health Benefits | Aon Consulting 200 East Randolph, Suite 900, Chicago, IL Tel: 312-381-2578 | Fax: 312-381-0136 Email: [EMAIL PROTECTED] Aon Consulting selected by the readers of Business Insurance as the âBest Employee Benefit Consulting Firmâ in 2006, 2007, and 2008 NOTE: The information contained in this transmission, including any attachment(s) is only for the use of the intended individual(s) or entity, and may contain information that is privileged and confidential. If the reader of this message is not an intended recipient, you are hereby notified that any dissemination, distribution, disclosure, or copying of this information is unauthorized and strictly prohibited. If you have received this communication in error, please contact the sender immediately by reply email and destroy all copies of the original message. [[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] Two overlaid density plots - Does order matter?
In the following code, the only difference between the two plots is the order the variables are plotted. In this case, the plot of cdata.den in plot #1 is different from its plot in #2. Specifically, cdata.den spans the x-axis from -5 to 30 in plot #1 and from 0 to 20 in plot #2. Does anyone understand why these two plots do not yield the same result? #Make density objects pre.den- density( preclaims[preclaims[,7]cc1 preclaims[,7]cc2,7], from = cc1, to = cc2) cdata.den-density(cdata,from=cc1,to=cc2) #Plot No. 1 x11() plot(cdata.den,col=1) lines(pre.den,col=2) #Plot No. 2 plot(pre.den,col=2) lines(cdata.den,col = 1) Regards, Stephen Collins, MPP | Analyst Health Benefits | Aon Consulting 200 East Randolph, Suite 900, Chicago, IL Tel: 312-381-2578 | Fax: 312-381-0136 Email: [EMAIL PROTECTED] [[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.