search for: mu2

Displaying 20 results from an estimated 75 matches for "mu2".

Did you mean: m32
2012 Oct 05
2
problem with convergence in mle2/optim function
Hello R Help, I am trying solve an MLE convergence problem: I would like to estimate four parameters, p1, p2, mu1, mu2, which relate to the probabilities, P1, P2, P3, of a multinomial (trinomial) distribution. I am using the mle2() function and feeding it a time series dataset composed of four columns: time point, number of successes in category 1, number of successes in category 2, and number of success in ca...
2012 Sep 27
0
problems with mle2 convergence and with writing gradient function
Dear R help, I am trying solve an MLE convergence problem: I would like to estimate four parameters, p1, p2, mu1, mu2, which relate to the probabilities, P1, P2, P3, of a multinomial (trinomial) distribution. I am using the mle2() function and feeding it a time series dataset composed of four columns: time point, number of successes in category 1, number of successes in category 2, and number of success in ca...
2012 Oct 11
2
model selection with spg and AIC (or, convert list to fitted model object)
...0L, 0L, 0L, 0L, 0L)), .Names = c("tv", "n1", "n2", "n3"), row.names = c(NA, -20L), class = "data.frame") # Negative log likelihood functions NLL1 <- function(par, y){ p1 <- par[1] p2 <- par[2] mu1 <- par[3] mu2 <- par[4] n1 <- y$n1 n2 <- y$n2 n3 <- y$n3 t <- y$tv P1 <- (p1*((-1 + exp(sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2)))*t))*((-mu2)*(mu2 - p1 + p2) + mu1*(mu2 + 2*p2)) - mu2*sqrt((mu1 + mu2 + p1 + p2)^2 - 4*(mu2*p1 + mu1*(mu2 + p2))) -...
2011 Jan 27
1
Errors in Integrate
Hello, I have written the function I would like to integrate in two ways: denfxn <- function(yy,vv,a2,b2,mu2) { pp <- 1-pnorm(yy/sqrt(vv)) part1 <- pp^(a2-1) part2 <- (1-pp)^(b2-1) part3 <- dnorm(yy,mu2,sqrt(vv)) return(part1*part2*part3) } denfxnorg <- function(yy,vv,a2,b2,mu2) { pp <- 1-pnorm(yy/sqrt(vv)) pp <- if (pp < .001) .001 else if (pp > ....
2007 Oct 23
1
How to avoid the NaN errors in dnbinom?
...duced I know from the help files that for dnbinom "Invalid size or prob will result in return value NaN, with a warning", but I am not able to find a workaround for this in my code to avoid it. I appreciate the help. Thanks. Below is the reproducible code: mixnbinom=function(y,k1,mu1,k2,mu2,prob,eps= 1/100000){ new.parms=c(k1,mu1,k2,mu2,prob) err=1 iter=1 maxiter=100 hist(y,probability=T,nclass=30,col="lightgrey",main="The EM algorithm") xvals=seq(min(y),max(y),1) lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+ (1-prob)*dnbinom(xvals,size=k2,mu=mu2),col="green...
2006 May 21
2
nls & fitting
...6 5 894.4272 130.390552 6 1264.9111 36.727069 7 1788.8544 52.848587 8 2449.4897 25.128742 9 3464.1016 7.531766 10 4472.1360 8.827367 11 6123.7244 6.600603 12 8660.2540 4.083339 I would like to fit N as a function of x according to a function depending on 9 parameters (A1,A2,A3,mu1,mu2,mu3,myvar1,myvar2,myvar3), namely N ~ (log(10)*A1/sqrt(2*pi)/log(myvar1)*exp(-((log(x/mu1))^2)/2/log(myvar1)/log(myvar1)) +log(10)*A2/sqrt(2*pi)/log(myvar2)*exp(-((log(x/mu2))^2)/2/log(myvar2)/log(myvar2)) +log(10)*A3/sqrt(2*pi)/log(myvar3)*exp(-((log(x/mu3))^2)/2/log(myvar3)/log(myvar3))) (i.e....
2009 Jul 17
6
Solving two nonlinear equations with two knowns
Dear R users, I have two nonlinear equations, f1(x1,x2)=0 and f2(x1,x2)=0. I try to use optim command by minimize f1^2+f2^2 to find x1 and x2. I found the optimal solution changes when I change initial values. How to solve this? BTW, I also try to use grid searching. But I have no information on ranges of x1 and x2, respectively. Any suggestion to solve this question? Thanks, Kate
2005 Nov 09
2
About: Error in FUN(X[[1]], ...) : symbol print-name too long
...ogram is to compare means of two independent samples that results in Beherens-Fisher posterior and in the model.file of WinBUGS "d2.bug" there is the following codes: model { for( i in 1 : 30 ) { x[i] ~ dnorm(mu1,sig1) } for( i in 1 : 30 ) { y[i] ~ dnorm(mu2,sig2) } mu1 ~ dnorm(50,1.0E-6) sig1 ~ dgamma(0.001,0.001) mu2 ~ dnorm(50,1.0E-6) sig2 ~ dgamma(0.001,0.001) lbda <- mu1 - mu2 } I??m a new user of WinBUGS and if someone detect error in the model codes too, I??m grateful. Thanks for help! Gilberto Matos. -----...
2013 Feb 01
2
How does this function print, why is n1 which equals 1 printed as 2?
...I have two questions, (i) how is the function printing when there is no code to print and (ii) how is n1 which equals 1 being reported as 2? I suspect there is something fundamental about R that I don't know. Thank you for the help. John library(epicalc) n.for.2means.js <- function (mu1, mu2, sd1, sd2, ratio = 1, alpha = 0.05, power = 0.8) { n1 <- (sd1^2 + sd2^2/ratio) * (qnorm(1 - alpha/2) - qnorm(1 - power))^2/(mu1 - mu2)^2 n1 <- round(n1) n2 <- ratio * n1 if (length(alpha) == 1) { alpha1 <- NULL } else { alpha1 <- alpha } if (length(power) ==...
2007 Mar 06
2
Estimating parameters of 2 phase Coxian using optim
Hi, My name is Laura. I'm a PhD student at Queen's University Belfast and have just started learning R. I was wondering if somebody could help me to see where I am going wrong in my code for estimating the parameters [mu1, mu2, lambda1] of a 2-phase Coxian Distribution. cox2.lik<-function(theta, y){ mu1<-theta[1] mu2<-theta[2] lambda1<-theta[3] p<-Matrix(c(1, 0), nrow=1, ncol=2) Q<-Matrix(c(-(lambda1 + mu1), 0, lambda1, -mu2), nrow=2, ncol=2) q<-Matr...
2006 Jun 07
2
help with combination problem
hello: I have 3 data.frame objects. First df object: Of dim (149,31). Columns 2:31 are marked as T1..T14 and N1..N16. Name T1 T2 N1 T3 N2 N3 N4 T4 mu1 10 10 9 10 9 9 8 10 mu2 11 11 9 11 9 9 9 11 ... muN 12 12 9 11 9 9 8 12 Second df object: of Dim (50000,31). Columns 2:31 are maked as T1...T14 and N1..N16. Name T1 T2 N1 T3 N2 N3 N4 T4 J1 2 3 20 2 22 21 29 3 J2 4 1 20...
2009 Mar 30
0
Problem in S4 object displaying from within a Java application using JRI
I am using JRI (Java R Interface) library in order to call R from within my Java application. But since the "rmu1" and "rmu2" ,see the following code, are objects of type S4 once i run the application the value of Null will be returned for both of them. On this regard, i would appreciate it if anyone can tell me how i am going to display and/ or convert these objects to Java objects or any other way to get the resul...
2013 Apr 09
0
[R-SIG-Finance] EM algorithm with R manually implemented?
...gt; likelihood of some observations is zero and therefore the log is -Inf. > > Where is my mistake? > > My code: > > # EM algorithm manually > # dat is the data > > > # initial values > pi1<-0.5 > pi2<-0.5 > mu1<--0.01 > mu2<-0.01 > sigma1<-0.01 > sigma2<-0.02 > loglik[1]<-0 > loglik[2]<-sum(pi1*(log(pi1)+ > log(dnorm(dat,mu1,sigma1))))+sum(pi2*(log(pi2)+log(dnorm(dat,mu2,sigma2)))) > > > > tau1<-0 > tau2<-0 > k<-1 > > # loop...
2008 Feb 15
1
Questions about EM algorithm
Dear all: Assume I have 3 distributions, x1, x2, and x3. x1 ~ normal(mu1, sd1) x2 ~ normal(mu2, sd2) x3 ~ normal(mu3, sd3) y1 = x1 + x2 y2 = x1 + x3 Now that the data I can observed is only y1 and y2. It is easy to estimate (mu1+m2), (mu1+mu3), (sd1^2+sd2^2) and (sd1^2+sd3^2) by EM algorithm since y1 ~ normal(mu1+mu2, sqrt(sd1^2+sd2^2)) and y2 ~ normal(mu1+mu3, sqrt(sd1^2+sd3^2)) However,...
2010 Jun 13
1
using latticeExtra plotting confidence intervals
...to have to the left side of the formula. This is the example code: library(lattice) library(latticeExtra) sample1<-rnorm(100,10,2) sample2<-rnorm(100,50,3) sample3<-rnorm(100,20,2) sample4<-rnorm(100,40,1) mu1<-mean(sample1) ci.upper1<-mu1+2*2 ci.lower1<-mu1-2*2 mu2<-mean(sample2) ci.upper2<-mu2+2*3 ci.lower2<-mu2-2*3 mu3<-mean(sample3) ci.upper3<-mu3+2*2 ci.lower3<-mu3-2*2 mu4<-mean(sample4) ci.upper4<-mu4+2*1 ci.lower4<-mu4-2*1 categories<-c("A","B") mu<-cbind(mu1,mu2,mu3,mu4) ci.upper<-cb...
2009 Oct 31
1
Help me improving my code
...age > bpw <- pennw$bp1000 > dur <- pennw$inuidur1 > fw <- factor(wage) > Ik <- model.matrix(~fw-1) > I1 <- Ik[,1] > I2 <- Ik[,2] > I3 <- Ik[,3] > I4 <- Ik[,4] > I5 <- Ik[,5] > yelmon <- function(theta,x){ + mu1 <- theta[1] + mu2 <- theta[2] + mu3 <- theta[3] + mu4 <- theta[4] + mu5 <- theta[5] + beta <- theta[6] + logL <- sum((Ik*log((exp(mu2-(x*beta))/(1+exp(mu2-(x*beta))))-(exp(mu1-(x*beta))/(1+exp(mu1-(x*beta))))))+(Ik*log((exp(mu3-(x*beta))/(1+exp(mu3-(x*beta))))-(exp(mu2-(x*beta))/(1+exp(mu2-(x*...
2010 Mar 20
2
EM algorithm in R
Please help me in writing the R code for this problem. I've been solving this for 4 days. It was hard for me to solve it. It's a simulation problem in R. The problem is My true model is a normal mixture which is given as 0.5 N(-0.8,1) + 0.5 N(0.8,1). This model has two components. I will get a random sample of size 100 from this model. I will do this 300 times. That means, I will have
2009 May 22
0
EM algorithm mixture of multivariate
...ha0*f1+(1-alpha0)*f2 scatterplot3d(y[,1], y[,2], p , highlight.3d=TRUE, col.axis="blue", col.grid="lightblue",main="val iniz mistura normali multivariata", angle=120, pch=20) #verosimiglianza iniziale l0<-sum(log(p)) l1<-l0 alpha<-alpha0 mu1<-mu01 mu2<-mu02 sd1<-sd01 sd2<-sd02 for (iter in 1:itermax) { #passo E for (i in 1:n) { tau[i,1]<-(alpha*f1[i])/p[i] tau[i,2]<-((1-alpha)*f2[i])/p[i] } #passo M alpha= mean(tau[,1]) mu1=colSums(tau[,1]*y)/sum(tau[,1]) mu2=colSums(tau[,2]*y)/sum(tau[,2]) ycen1<-(y-mu1) ycen2<-(y-m...
2008 Apr 05
2
How to improve the "OPTIM" results
...11764954, 5.92662106, 1.03932953, -6.21987657, -0.54763352, 0.20263192) # data theta0= c(log(2),0,c(0,-.3,.3),log(c(10,.05,.05))) # initial value(In fact, true parameter value) n = length(x) fr2 = function(theta) { a1 = theta[1]; a2 = theta[2] mu1 = theta[3]; mu2 = theta[4]; mu3 = theta[5] g1 = theta[6]; g2 = theta[7]; g3 = theta[8] w1=exp(a1)/(1+exp(a1)+exp(a2)) w2=exp(a2)/(1+exp(a1)+exp(a2)) w3=1-w1-w2 obj =((w1^2)/(2*sqrt(exp(g1)*pi)) + (w2^2)/(2*sqrt(exp(g2)*pi)) + (w3^2)/(2*sqrt(exp(g2)*pi)) + 2*w1*w2*dnorm((mu1-mu2)/sq...
2008 Apr 05
2
How to improve the "OPTIM" results
...11764954, 5.92662106, 1.03932953, -6.21987657, -0.54763352, 0.20263192) # data theta0= c(log(2),0,c(0,-.3,.3),log(c(10,.05,.05))) # initial value(In fact, true parameter value) n = length(x) fr2 = function(theta) { a1 = theta[1]; a2 = theta[2] mu1 = theta[3]; mu2 = theta[4]; mu3 = theta[5] g1 = theta[6]; g2 = theta[7]; g3 = theta[8] w1=exp(a1)/(1+exp(a1)+exp(a2)) w2=exp(a2)/(1+exp(a1)+exp(a2)) w3=1-w1-w2 obj =((w1^2)/(2*sqrt(exp(g1)*pi)) + (w2^2)/(2*sqrt(exp(g2)*pi)) + (w3^2)/(2*sqrt(exp(g2)*pi)) + 2*w1*w2*dnorm((mu1-mu2)/sq...