[R] Bayesian functions for mle2 object
Hi everybody, I'm interested in evaluating the effect of a continuous variable on the mean and/or the variance of my response variable. I have built functions expliciting these and used the 'mle2' function to estimate the coefficients, as follows: func.1 - function(m=62.9, c0=8.84, c1=-1.6) { s - c0+c1*(x) -sum(dnorm(y, mean=m, sd=s,log=T)) } m1 - mle2(func.1, method=SANN) However, the estimation of the effect of x on the variance of y usually has dealt some troubles, resulting in no convergencies or sd of estimates extremely huge. I tried using different optimizers, but I still faced the some problems. When I had similar troubles in 'GLMM' statistical universe, I used bayesian functions to solve this problem, enjoyning the flexibility of different start points to reach the maximum likelihood estimates. However, I have no idea which package or which function to use to solve the specific problem I'm facing now. Does anyone have a clue? Thanks in advance Gustavo Requena PhD Student - Laboratory of Arthropod Behavior and Evolution Universidade de Sao Paulo - Brazil -- View this message in context: http://r.789695.n4.nabble.com/Bayesian-functions-for-mle2-object-tp3776442p3776442.html Sent from the R help mailing list archive at Nabble.com. __ 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] Logistic regression with factorial effect
Hello, I’d like to evaluate the temporal effect on the relationship between a continuous variable (e.g. size) and the probability of mate success. Initially I was trying to do a logistic regression model incorporating the temporal effect, but I don’t know if that is the best option. I simulated some data and that’s the problem: rep(c(Jan,Feb,Mar,Apr,May), each=20) - month as.factor(month) rep(LETTERS[seq(1:20)], 5) - ind rep(sort(rnorm(20, 5.5, 0.2)), 5) - size size c(c(rep(0,12), rep(1,8)), c(rep(0,12), rep(1,8)), c(rep(c(0,1), 10)), c(rep(1,8), rep(0,12)), c(rep(1,8), rep(0,12))) - success1 success1 With the object ‘success1’, only the highest values of size are successful at the two first months, but only the lowest values of size are successful at the two last months. So, the overall effect of size on the successful probability should not exist, but if we consider the interaction between size and time, we should be able to see that effect. glm(success1 ~ size, family=binomial) - test1.1 glmer(success1 ~ size + (1|ind), family=binomial) - test2.1 glmer(success1 ~ size + month + (1|ind), family=binomial) - test3.1 glmer(success1 ~ size : month + (1|ind), family=binomial) - test4.1 However, the expected result is not observed in the output of all these models. Using a model selection approach and comparing the AIC values of all models, it seems that ‘test1.1’ model is the most likely. All the deviances are almost at the same level and the differences in AIC values are due for the new parameters added. Given the data was simulated to generate differences between models and model ‘test4.1’ is supposed to be the best one, I’m probably doing something wrong. Has anyone faced this kind of problem? Or has anyone any idea how to solve that? Thanks and Regards Gustavo Requena PhD student - Laboratory of Arthropod Behavior and Evolution Universidade de São Paulo http://ecologia.ib.usp.br/opilio/gustavo.html -- View this message in context: http://r.789695.n4.nabble.com/Logistic-regression-with-factorial-effect-tp3049208p3049208.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] several Filled.contour plots on the same device...
Hi Alexis! I had the same problem you faced and the solution I found was modifying the layout function. That’s an example: f1 - function (a, x) {2.15*a -0.25*x} f2 - function (a,x) {exp(2.36*a - 0.04*x)} a1 - seq(from=5.2, to=6.2, by=(6.2-5.2)/19) b1 - seq(0,32) zeros - rep(0, length(a)*length(b)) mat1 - matrix(zeros, ncol=length(a), nrow=length(b)) for (i in 1:20) { for(j in 1:33) { est - f1(a=a1[i], x=b1[j]) mat1[j,i] - est } } mat2 - matrix(zeros, ncol=length(a), nrow=length(b)) for (i in 1:20) { for(j in 1:33) { est - f2(a=a1[i], x=b1[j]) mat2[j,i] - est } } mar.orig - (par.orig - par(c(mar, las, mfrow)))$mar w - (3 + mar.orig[2L]) * par(csi) * 2.54 a - layout(matrix(c(2, 1,0,4,3), ncol = 5), heights=lcm(20), widths = c(1.2, lcm(w/1.75),0.05, 1, lcm(w/1.75))) layout.show(a) #device dividido ppara apresentar duas figuras compostas #Scale 1 par(las = 1) mar - mar.orig mar[4L] - mar[2L] mar[2L] - 1 par(mar = mar) lev.m.vol - pretty(range(mat1),4) plot.new() plot.window(xlim=c(0, 1), ylim=range(lev.m.vol), xaxs=i, yaxs=i) rect(0, lev.m.vol[-length(lev.m.vol)], 1, lev.m.vol[-1L], col = gray((6:1)/6)) axis(4, cex.axis=1.2) mtext(Mean, at=2.5, side=3, line=1, adj=1, cex=1.35) #Graph1 mar - mar.orig mar[4L] - 1 par(mar = c(6,8,4,2)) plot.new() plot.window(xlim=range(b1, finite = TRUE), ylim=range(a1, finite = TRUE), , xaxs = i, yaxs = i, asp = NA) storage.mode(mat1) - double .Internal(filledcontour(as.double(b1), as.double(a1), mat1, as.double(lev.m.vol), col = gray((6:1)/6))) box() axis(1, at=seq(0,32,by=4),seq(0, 32, by =4), cex.axis=1.2) axis(2, at=seq(5.2, 6.2, by =0.2),labels=c(5.2, 5.4, 5.6, 5.8, 6.0, 6.2), cex.axis=1.2) mtext(X, side=1, line=3.5, cex =1.2) mtext(Y, at=5.62, side=2, line=3.5, cex =1.2, las=0) mtext(A, at=1, side=3, line=1, cex =2.2) #Scale 2 par(las = 1) mar - mar.orig mar[4L] - mar[2L] mar[2L] - 1 par(mar = mar) lev.sd.vol - pretty(range(mat2),4) plot.new() plot.window(xlim=c(0, 1), ylim=range(lev.sd.vol), xaxs=i, yaxs=i) rect(0, lev.sd.vol[-length(lev.sd.vol)], 1, lev.sd.vol[-1L], col = gray((6:1)/6)) axis(4, cex.axis=1.2) mtext(Standard, at=3.3, side=3, line=2.5, adj=1, cex=1.25) mtext(deviation, at=3.3, side=3, line=1, adj=1, cex=1.25) #Graph2 mar - mar.orig mar[4L] - 1 par(mar = c(6,1,4,2)) plot.new() plot.window(xlim=range(b1, finite = TRUE), ylim=range(a1, finite = TRUE), , xaxs = i, yaxs = i, asp = NA) storage.mode(mat2) - double .Internal(filledcontour(as.double(b1), as.double(a1), mat2, as.double(lev.sd.vol), col = gray((6:1)/6))) box() axis(1, at=seq(0,32,by=4),seq(0, 32, by =4), cex.axis=1.2) axis(2, at=seq(5.2, 6.2, by =0.2),labels=c(5.2, 5.4, 5.6, 5.8, 6.0, 6.2), cex.axis=1.2) mtext(X, side=1, line=3.5, cex =1.2) mtext(B, at=1, side=3, line=1, cex =2.2) I wish it could help you Gustavo Requena PhD student - Laboratory of Arthropod Behavior and Evolution Universidade de São Paulo http://ecologia.ib.usp.br/opilio/gustavo.html -- View this message in context: http://r.789695.n4.nabble.com/several-Filled-contour-plots-on-the-same-device-tp819040p2332041.html Sent from the R help mailing list archive at Nabble.com. __ 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.