I am trying to create a histogram of a variable with superimposed the lines of the 2 gammas distribution and the mixture of those two. But when I insert the following code:
hist(age, breaks = 50,freq = FALSE)
lines(seq(min(age),max(age),length=length(age)),age.GA.2[["prob"]][1]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat1, sigma = sigma.hat1),lty=2,lwd=3,col=2)
lines(seq(min(age),max(age),length=length(age),age.GA.2[["prob"]][2]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat2, sigma = sigma.hat2),lty=2,lwd=3,col=3)
lines(seq(min(age),max(age),length=length(age)),
age.GA.2[["prob"]][1]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat1, sigma = sigma.hat1) +
age.GA.2[["prob"]][2]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat2, sigma = sigma.hat2),
lty = 1, lwd = 3, col = 1)
I got this error result:
> hist(age, breaks = 50,freq = FALSE)
> lines(seq(min(age),max(age),length=length(age)),age.GA.2[["prob"]][1]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat1, sigma = sigma.hat1),lty=2,lwd=3,col=2)
> lines(seq(min(age),max(age),length=length(age),age.GA.2[["prob"]][2]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat2, sigma = sigma.hat2),lty=2,lwd=3,col=3)
+ lines(seq(min(age),max(age),length=length(age)),
Errore: unexpected symbol in:
"lines(seq(min(age),max(age),length=length(age),age.GA.2[["prob"]][2]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat2, sigma = sigma.hat2),lty=2,lwd=3,col=3)
lines"
> age.GA.2[["prob"]][1]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat1, sigma = sigma.hat1) +
+ age.GA.2[["prob"]][2]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat2, sigma = sigma.hat2),
Errore: unexpected ',' in:
"age.GA.2[["prob"]][1]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat1, sigma = sigma.hat1) +
age.GA.2[["prob"]][2]*dGA(seq(min(age),max(age),length=length(age)), mu = mu.hat2, sigma = sigma.hat2),"
> lty = 1, lwd = 3, col = 1)
Errore: unexpected ',' in "lty = 1,"
I still haven't figured out what is the problem. I took the exact code from a file given us by the professor, I just changed the values for the database and the fits.