From 5b8375628823ce465eec34cb1ac584762a8aa06c Mon Sep 17 00:00:00 2001 From: Alberto Mengual <81755436+aldamepi@users.noreply.github.com> Date: Thu, 27 Apr 2023 03:07:32 +0200 Subject: [PATCH] corregido shiny binomial negativa --- teoria/Tema_3_1_Notables.Rmd | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/teoria/Tema_3_1_Notables.Rmd b/teoria/Tema_3_1_Notables.Rmd index 7fad05b..17641c4 100644 --- a/teoria/Tema_3_1_Notables.Rmd +++ b/teoria/Tema_3_1_Notables.Rmd @@ -1977,10 +1977,10 @@ fluidPage( fluidRow( column(6, sliderInput("n_nbinom", label = "Número de éxitos n:", - min = 1, max = 50, value =20 , step = 1)), + min = 1, max = 50, value =2 , step = 1)), column(6, sliderInput("p_nbinom", label = "Probabilidad de un éxito p:", - min = 0.01, max = 0.99, value = 0.8, step = 0.01) + min = 0.01, max = 0.99, value = 0.1, step = 0.01) ) ) ) @@ -1988,16 +1988,17 @@ fluidRow( renderPlot({ n=input$n_nbinom pr=input$p_nbinom + r = qnbinom(0.999,n,pr) - qnbinom(0.001,n,pr) par(mfrow=c(1,2)) - aux=rep(0,(n+1)*2) - aux[seq(2,(n+1)*2,2)]=dnbinom(c(0:n),size=n,prob=pr) - plot(x=c(0:n),y=dnbinom(c(0:n),size=n,prob=pr), - ylim=c(0,1),xlim=c(-1,n+1),xlab="x", + aux=rep(0,(r+1)*2) + aux[seq(2,(r+1)*2,2)]=dnbinom(c(0:r),size=n,prob=pr) + plot(x=c(0:r),y=dnbinom(c(0:r),size=n,prob=pr), + ylim=c(0,1.3*aux[which.max(aux)]),xlim=c(-1,r+1),xlab="x", main=paste0(c("Función de probabilidad\n BN(n=",n,",p=",pr,")"),collapse = "")) - lines(x=rep(0:n,each=2),y=aux, type = "h", lty = 2,col="blue") - curve(pnbinom(x,size=n,p=pr), - xlim=c(-1,n+1),col="blue", + lines(x=rep(0:r,each=2),y=aux, type = "h", lty = 2,col="blue") + curve(pnbinom(x,size=n,prob=pr), + xlim=c(-1,r+1),col="blue", main=paste0(c("Función de distribución\n BN(n=",n,",p=",pr,")"), collapse = "")) par(mfrow=c(1,1))