## C?digo tesis Jose
ajuste.beta<-function(teta,valores=valores){
  alfa<-teta[1]
  beta<-teta[2]
  cuantil0.05<-valores[1]
  cuantil0.95<-valores[3]
  
  media<-valores[2]
  cuant1.teo<-qbeta(0.05,alfa,beta)
  cuant2.teo<-qbeta(0.95,alfa,beta)
  media.teo<-alfa/(alfa+beta)
  res<-(cuantil0.05-cuant1.teo)^2
  +(cuantil0.95-cuant2.teo)^2
  +(media-media.teo)^2
  return(res)
}

valores<-c(0.005,0.01,0.02)
optim(c(1,1),ajuste.beta,method="L-BFGS-B",
      lower=c(1,1)/1000000,upper=c(10,10),
      valores=valores)


############################

library(ggplot2)

library(ggplot2)

x <- 1:9
y <- c(22.56, 40.07, 55.93, 68.97, 80.04, 88.52, 93.48, 97.09, 100)

ggplot(data = data.frame(x = x, y = y), aes(x = x, y = y)) +
  geom_point(color = "blue") +
  geom_line(color = "blue", size = 0.8) +  # Increase the size parameter to make the line thicker
  scale_x_continuous(breaks = 1:9) +
  xlab("Principal components") +
  ylab("Cumulative variability explained (%)") +
#  ggtitle("Cumulative variability explained by principal components") +
  theme_bw()

