Advertisement
nm9505

CALCULADOR DE ESTADISTICOS

Sep 8th, 2022
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.70 KB | Science | 0 0
  1. using System;
  2. //using System.IO;
  3. using System.Threading.Tasks;
  4. using Xamarin.Forms;
  5. //using Android.Views.InputMethods;
  6.  
  7. [assembly:ExportFont("digital-7.ttf")]
  8. namespace CalculadorDeEstadisticos
  9. {
  10.     public partial class MainPage : ContentPage
  11.     {
  12.         public MainPage()
  13.         {
  14.             InitializeComponent();
  15.            
  16.         }
  17.         private decimal Entrada1; int A=1,B=1; int c=0;
  18.         private string Operacion; double Media; double CU=0;
  19.         double M=0; string MedText=""; double?[] x; string orden="";
  20.         private bool Operador; int N=0; int[] f; string Cuartiles="";
  21.         double[] Datos; string frec=""; string MO="";
  22.         int dec=0; decimal b = 2.11M; double sturges=0; double Interval=0;
  23.         string DISPERSION; string Sesgo=""; double sk=0;
  24.         string AgrupD=""; string AgrupC=""; string CURTOSIS="";
  25.        
  26.         protected override void OnAppearing()
  27.         {
  28.             Entero.Focus();
  29.             ResED.IsVisible=false;
  30.         }
  31.         private async void BtEntClick(object sender, EventArgs e)
  32.         {
  33.             try
  34.             {
  35.                 double Sum=0;
  36.                 //double Datos=new Datos[];
  37.                 N = int.Parse(Entero.Text);
  38.                 Datos = new double[N];
  39.                 if (N>1)
  40.                 {
  41.                     ResED.Text=$"Número de Datos = {N}";
  42.                     marco.IsVisible=true;
  43.                     ResED.IsVisible=true;
  44.                     Inicio2:
  45.                     await Task.Delay(10);
  46.                     int muestreo = int.Parse (await DisplayPromptAsync("Enteros aleatorios: 1 ", "Muestreo manual: 2", keyboard : Keyboard.Numeric));
  47.                     if(muestreo!=1 & muestreo!=2)
  48.                     {
  49.                         goto Inicio2;
  50.                     }
  51.                     switch(muestreo)
  52.                     {
  53.                         case 1:
  54.                         {
  55.                             string[] extremo=new string[2];
  56.                             extremo[0]="Menor"; extremo[1]="Mayor";
  57.                             int[] extremos = new int[2];
  58.                             for (int i=0; i<2; i++)
  59.                             {
  60.                                 int Ingreso = int.Parse (await DisplayPromptAsync($"Ingrese valor", $"{extremo[i]}", keyboard : Keyboard.Numeric));
  61.                                 extremos[i]=Ingreso;
  62.                             }
  63.                             Random Num = new Random();
  64.                             for(int a=0; a<N; a++)
  65.                             {
  66.                                 if (extremos[1] < extremos[0])
  67.                                 {
  68.                                     Datos[a] = Num.Next(extremos[1],extremos[0] + 1);
  69.                                     Sum = Sum + Datos[a];
  70.                                 }
  71.                                 else
  72.                                 Datos[a] = Num.Next(extremos[0],extremos[1] + 1);
  73.                                 Sum = Sum + Datos[a];
  74.                                 Media = Math.Round(Sum/Convert.ToDouble(N),2);
  75.                             }
  76.                         }
  77.                         break;
  78.                         default:
  79.                         await Task.Delay(10);
  80.                         dec = int.Parse (await DisplayPromptAsync("¿ Cifras decimales que diferencian los datos ?", "Si los datos son enteros, ingrese 0", keyboard : Keyboard.Numeric));
  81.                         for (int i=0; i<N; i++)
  82.                         {
  83.                             await Task.Delay(10);
  84.                             string resul = await DisplayPromptAsync($"Ingrese Dato {i+1} ", $"De {N} valores", keyboard : Keyboard.Numeric);
  85.                             if(resul==null)
  86.                             {
  87.                                 Datos[i]=0;
  88.                             }
  89.                             try
  90.                             {
  91.                                 Datos[i]=double.Parse(resul);
  92.                                 Sum = Sum + Datos[i];
  93.                                 Media = Math.Round(Sum/Convert.ToDouble(N),2);
  94.                             }
  95.                             catch(FormatException ex)
  96.                             {
  97.                                 await DisplayAlert("Valor inpropio en \nasignación", ex.Message, "Reintentar");
  98.                             }
  99.                         }
  100.                         break;
  101.                     }
  102.                     for (int i = 0; i < N; i++) //Ordenamiento
  103.                     {
  104.                         for (int k = 0; k <= N - 2; k++)
  105.                         {
  106.                             if (Datos[k] > Datos[k + 1])
  107.                             {
  108.                                 double y = Datos[k];
  109.                                 Datos[k] = Datos[k + 1];
  110.                                 Datos[k + 1] = y;
  111.                             }
  112.                         }
  113.                     }
  114.                 }
  115.                 //Calculo de segundo y cuarto momento
  116.                 double Ds; double SM = 0; double X = Math.Round(Sum / N, 2); double CM = 0;
  117.                 for (int j = 0; j < N; j++)
  118.                 {
  119.                     SM = SM + Math.Pow(Datos[j] - Media, 2);
  120.                     CM = CM + Math.Pow(Datos[j] - Media, 4);
  121.                 }
  122.                 double VAR = SM/(N-1);
  123.                 Ds = Math.Sqrt(SM/(N-1));
  124.                 if (Ds != 0)
  125.                 {
  126.                     CU = CM / ((N-1) * Math.Pow(Ds, 4));
  127.                 }
  128.                 b = Math.Round(Convert.ToDecimal(Ds), 2);
  129.                 //Calculo de frecuencias simples
  130.                 x = new double? [Datos.Length];
  131.                 f = new int [Datos.Length];
  132.                 int Max = 0;
  133.                 for (int i = 0; i < N; i++)
  134.                 {
  135.                     c = 0; f[i] = 0;
  136.                     for (int k = 0; k < N; k++)
  137.                     {
  138.                         if (Datos[k] == Datos[i])
  139.                         {
  140.                             ++c;
  141.                             if (caso(Datos[i]))
  142.                             {
  143.                                 x[i] = Datos[i];
  144.                             }
  145.                         }
  146.                         if (c >= Max)
  147.                         {
  148.                             Max = c;
  149.                         }
  150.                     }
  151.                     f[i] = c;
  152.                     double r = Math.Round(100 * Convert.ToDouble(f[i]) / Convert.ToDouble(N), 1);
  153.                     if (x[i] != null)
  154.                     {
  155.                         frec= frec + $"\n({x[i]}  →  {c}  → {r} %)";
  156.                     }
  157.                 }
  158.                 bool caso(double valor)
  159.                 {
  160.                     for (int i = 0; i < x.Length; i++)
  161.                     {
  162.                         if (x[i] == valor)
  163.                         {
  164.                             return false;
  165.                         }
  166.                     }
  167.                     return true;
  168.                 }
  169.                 // Visualizacion de valores modales posibles
  170.                 string modas = "";
  171.                 int z = 0; int s = 0; int us = 1;
  172.                 for (int j = 0; j < x.Length; j++)
  173.                 {
  174.                     if (f[j] == Max && Max > 1)
  175.                     {
  176.                         z++;
  177.                         if (x[j] != null)
  178.                         {
  179.                             s++;
  180.                            
  181.                             MO=MO+$"\nModa {s} = {x[j]}";
  182.                             us = j;
  183.                             modas = modas + Convert.ToString(x[j]) + ", ";
  184.                         }
  185.                     }
  186.                 }
  187.                 if (Max != 1)
  188.                 {
  189.                     MO=MO+$"\nFrecuencia modal = {Max}";
  190.                 }
  191.                 string modas1 = modas;
  192.                 if (s > 1)
  193.                 {
  194.                     modas1 = modas.TrimEnd(' ');
  195.                     modas1 = modas1.TrimEnd(',');
  196.                     string umoda = Convert.ToString(x[us]);
  197.                     int ulm = umoda.Length + 1;
  198.                     modas1 = modas1.Insert(modas1.Length - ulm, " y");
  199.                 }
  200.                 if (Max == 1)
  201.                 {
  202.                     modas = null;
  203.                     MO="No existe valor modal alguno.\n La muestra tiende a una distribución Uniforme, ningún valor se repite.";
  204.                 }
  205.                 else if (Max > 1 && s == 2)
  206.                 {
  207.                     MO=MO+$"\nBimodal: {modas1} con una frecuencia de {Max} las dos.";
  208.                 }
  209.                 else if (Max > 1 && s > 2)
  210.                 {
  211.                     MO=MO+$"\nMultimodal: {modas1} con una frecuencia de {Max} cada una.";
  212.                 }
  213.                 //Condicionales para determinar la Mediana
  214.                 if (N % 2 == 1)
  215.                 {
  216.                     M = Datos[((N + 1) / 2) - 1];
  217.                     MedText=$"La mediana es {M} y pertenece a la muestra";
  218.                 }
  219.                 if (N % 2 == 0 && Datos[N / 2 - 1] == Datos[N / 2])
  220.                 {
  221.                     M = Datos[N / 2];
  222.                     MedText=$"La mediana es {M} y pertenece a la muestra";
  223.                 }
  224.                 else if (N % 2 == 0 && Datos[N / 2 - 1] != Datos[N / 2])
  225.                 {
  226.                     M = (Datos[N / 2 - 1] + Datos[N / 2]) / 2;
  227.                     MedText=$"La mediana es {M} y no pertenece a la muestra";
  228.                 }
  229.                 //CÁLCULO parámetros de DISPERSIÓN
  230.                 double unit = Math.Pow(10, -dec);
  231.                 double range = (Datos[N - 1] - Datos[0]) + unit;
  232.                 DISPERSION=$"Xmax = {Datos[N - 1]}, Xmin = {Datos[0]}";
  233.                 DISPERSION=DISPERSION+$"\nRANGO = {range}";
  234.                 if (N >= 8)
  235.                 {
  236.                     sturges = Math.Round(1 + 3.3 * Math.Log10(N), 0);
  237.                     DISPERSION=DISPERSION+$"\nIntervalos de clase sugeridos según Sturges:\n#CLASES = Math.Round(1 + 3.3 x Log {N},0) = {sturges}";
  238.                 }
  239.                 Interval = Math.Round(Convert.ToDouble(range * Math.Pow(10, dec)) / sturges, 0) * unit;
  240.                 DISPERSION=DISPERSION+$"\nLONGITUD DE INTERVALO:\n I = Math.Round(RANGO/#clases,0) = {Interval}";
  241.                 DISPERSION=DISPERSION+$"\nVarianza S² = {Math.Round(VAR,2)}";
  242.                 DISPERSION=DISPERSION+$"\nDesviación estándar S = {b} unidades.";
  243.                 DISPERSION=DISPERSION+"\nRELACIÓN DE 'CHEBYSHEV':";
  244.                 DISPERSION=DISPERSION+$"\nμ = {Media}, S = {b}";
  245.                 if (Ds!=0)
  246.                 {  
  247.                     int tn=1;
  248.                     do
  249.                     {
  250.                         int ch=0;
  251.                         double ms =Math.Round(Media - tn*Convert.ToDouble(b),2); double Ms  = Math.Round(Media + tn*Convert.ToDouble(b),2);
  252.                         for(int j=0; j<N; j++)
  253.                         {
  254.                             if (Datos[j]>=ms & Datos[j]<=Ms)
  255.                             {
  256.                                 ch++;
  257.                             }
  258.                         }
  259.                         double chr = 100*Math.Round(Convert.ToDouble(ch)/Convert.ToDouble(N),2);
  260.                         if (tn==1)
  261.                         {
  262.                             DISPERSION=DISPERSION+$"\n(μ ± S) = ({ms}, {Ms}), {ch} de {N} se encuentran en este intervalo, ≈ un {chr}%.";
  263.                             if (ch==N){break;}
  264.                             goto next;
  265.                         }
  266.                         DISPERSION=DISPERSION+$"\n(μ ± {tn}S) = ({ms}, {Ms}), {ch} de {N} se encuentran en este intervalo, ≈ un \t{chr}%.";
  267.                         if (ch==N){break;}
  268.                         next:
  269.                         tn++;
  270.                     } while (tn<=3);
  271.                 }
  272.                 else
  273.                 {
  274.                     DISPERSION=DISPERSION+"\nDesviación estándar nula, no existe relación de Chebyshev";
  275.                 }
  276.                 //Determinación de ASIMETRIA O SESGO
  277.                 Sesgo="sk=(N/(N-1)(N-2))(Σ((x - Media)/s)³";
  278.                 double TM=0;
  279.                 for(int i=0; i<N; i++)
  280.                 {
  281.                     TM = TM+Math.Pow((Datos[i]-Media)/Ds,3);
  282.                 }
  283.                 sk = Math.Round(N*TM/((N-1)*(N-2)),2);
  284.                 if (Max == 1)
  285.                 {
  286.                     Sesgo=Sesgo+"\nLa muestra no posee asimetria alguna, porque muestra una tendencia Uniforme. Ningun valor se repite";
  287.                 }
  288.                 if (Ds == 0)
  289.                 {
  290.                     Sesgo=Sesgo+"\nsk es Indefinida porque S = 0.";
  291.                 }
  292.                 else if (Max > 1 && s == 1)
  293.                 {
  294.                     if (Math.Abs(sk) <= 0.2)
  295.                     {
  296.                         if(Math.Abs(Media-Convert.ToDouble(x[us]))<0.2)
  297.                         {
  298.                             Sesgo=Sesgo+$"\n sk = {sk} ¡ Asimetría o sesgo mínimo !!:";
  299.                             Sesgo=Sesgo+"\nMuestra con tendencia simétrica, o tendencia t-Student: Distribución unimodal con Media, Mediana y Moda muy cercanas entre sí.";
  300.                         }
  301.                         else
  302.                         {
  303.                             if(sk<0)
  304.                             {  
  305.                                 Sesgo=Sesgo+$"\nMuestra ligeramente sesgada a la izquierda, con sk = {sk}";
  306.                             }
  307.                             else if(sk>0)
  308.                             {
  309.                                 Sesgo=Sesgo+$"\nMuestra ligeramente sesgada a la derecha, con sk = {sk}";
  310.                             }
  311.                         }
  312.                     }
  313.                     else if (Math.Abs(sk) > 0.2 && sk<0 )
  314.                     {
  315.                         Sesgo=Sesgo+$"\nMuestra unimodal con sesgo {sk} negativo o tendencia asimétrica con sesgo hacia la izquierda.";
  316.                     }
  317.                     else if (Math.Abs(sk) > 0.2 && sk>0)
  318.                     {
  319.                         Sesgo=Sesgo+$"\nMuestra unimodal con sesgo {sk} positivo o tendencia asimétrica con sesgo hacia la derecha.";
  320.                     }
  321.                     else
  322.                     {
  323.                         Sesgo=Sesgo+$"\nMuestra con sesgo sk = {sk}";
  324.                     }
  325.                 }
  326.                 else if (Max > 1 && s > 1)//Si existe moda y hay más de una.
  327.                 {
  328.                     Sesgo=Sesgo+$"\nEl valor del sesgo {sk}, podría no ser significativo porque la muestra presenta {s} picos modales en {modas1} los cuales forman altibajos.";
  329.                 }
  330.                 else
  331.                 {
  332.                     Sesgo=Sesgo+$"\nMuestra con tendencia uniforme. El valor sk = {sk} es irrelevante";
  333.                 }
  334.                 //Determinación de CURTOSIS
  335.                 CURTOSIS="CURTOSIS (Ω):";
  336.                 CURTOSIS=CURTOSIS+"\nAglomeración entorno a la media. Tipos:";
  337.                 CURTOSIS=CURTOSIS+"Leptocúrtica Ω > 3 (Punteaguda)";
  338.                 CURTOSIS=CURTOSIS+"\nMesocúrtica Ω = 3 (Curva Normal)";
  339.                 CURTOSIS=CURTOSIS+"\nFlaticúrtica Ω < 3 (Achatada)";
  340.                 CURTOSIS=CURTOSIS+"\nPara esta muestra:";
  341.                 if (Ds == 0)
  342.                 {
  343.                     CURTOSIS=CURTOSIS+"\n Ω es Indefinida, porque S = 0.";
  344.                 }
  345.                 if (Ds != 0)
  346.                 {
  347.                     CURTOSIS=CURTOSIS+$"\n Ω = {Math.Round(CU, 3)}";
  348.                 }
  349.                 if(CU>0 && Max>1 && s>1 || modas==null)
  350.                 {
  351.                     CURTOSIS=CURTOSIS+"\nEl valor de Ω no se puede caracterizar geométricamente, porque la muestra presenta más de una cumbre modal, o bien es una muestra que tiende a una distribución uniforme.";
  352.                 }
  353.                 else if (CU > 3 && Ds!=0)
  354.                 {
  355.                     CURTOSIS=CURTOSIS+$"\nMuestra con tendencia leptocúrtica, con un exceso (pico de cumbre) de \nΩ - 3 = {Math.Round(CU - 3, 3)}, por encima de la curva Normal.";
  356.                     if (CU - 3 < 0.2 & CU - 3 >= 0.1)
  357.                     {
  358.                         CURTOSIS=CURTOSIS+"\nAunque el exceso es mínimo, pudiendo considerarse 'cuasinormal' ";
  359.                     }
  360.                 }
  361.                 else if (Math.Abs(CU - 3) < 0.1 && Ds!=0)
  362.                 {
  363.                     CURTOSIS=CURTOSIS+"\nMuestra con tendencia Mesocúrtica o de curva Normal(Ω = 3).";
  364.                 }
  365.                 else if (CU < 3 && Ds != 0)
  366.                 {
  367.                     CURTOSIS=CURTOSIS+$"\nMuestra con tendencia flaticúrtica, con una disminución de cumbre \n3 - Ω = {Math.Round(3 - CU, 3)}, por debajo de la curva Normal.";
  368.                     if (3 - CU < 0.2 && 3 - CU >= 0.1)
  369.                     {
  370.                         CURTOSIS=CURTOSIS+"\nAunque la disminución es mínima, pudiendo considerarse 'cuasinormal'.";
  371.                     }
  372.                 }
  373.                 //STURGES-D: Agrupación Discreta
  374.                 AgrupD="AGRUPACION DISCRETA SUGERIDA";
  375.                 double Inicial = Datos[0];
  376.                 double Final = 0; int Fam=0;
  377.                 AgrupD=AgrupD+$"\nLONGITUD DE INTERVALO I = {Interval}";
  378.                 if(N<8)
  379.                 {
  380.                     AgrupD=AgrupD+$"\nLa agrupación es inpropia para N < 8";
  381.                     await Task.Delay(15);
  382.                     await DisplayAlert("La agrupación es impropia para \nN < 8", "","Aceptar");
  383.                 }
  384.                 AgrupD=AgrupD+"\nClase → Marca  →  f → F  → f%";
  385.                 do
  386.                 {
  387.                     Final = Inicial + Interval;
  388.                     Final = Math.Round(Final, dec);
  389.                     double Xm = (Inicial + Final) / 2;
  390.                     int Fm = 0;
  391.                     for (int t = 0; t < N; t++)
  392.                     {
  393.                         if (Datos[t] >= Inicial && Datos[t] <= Final)
  394.                         {
  395.                             Fm++;
  396.                         }
  397.                     }
  398.                     Fam = Fam + Fm;
  399.                     double Fp = Math.Round(Convert.ToDouble(Fm) * 100 / Convert.ToDouble(N), 2);
  400.                     AgrupD=AgrupD+$"\n{Inicial} - {Final} | {Xm} | {Fm} | {Fam} | {Fp}";
  401.                     Inicial = Math.Round(Final + unit, dec);
  402.                 } while (Final < Datos[N - 1]);
  403.                 //STURGES-C: Agrupación Contínua
  404.                 AgrupC="AGRUPACION CONTINUA SUGERIDA";
  405.                 AgrupC=AgrupC+$" LONGITUD DE INTERVALO:\n I + unity = {Interval + unit}";
  406.                 if(N<8)
  407.                 {
  408.                     AgrupD=AgrupD+$"\nLa agrupación es inpropia para N < 8";
  409.                 }
  410.                 double LRI = Datos[0] - 5 * Math.Pow(10, -dec - 1);
  411.                 double LRF = 0; double Fcam=0;
  412.                 double Xmr = 0; int Fmr = 0;
  413.                 AgrupC=AgrupC+"\nClase → Marca  →  f → F  → f%";
  414.                 do
  415.                 {
  416.                     LRF = LRI + Interval + 1 * unit;
  417.                     LRF = Math.Round(LRF, dec + 1);
  418.                     Xmr = (LRI + LRF) / 2;
  419.                     Fmr = 0;
  420.                     for (int t = 0; t < N; t++)
  421.                     {
  422.                         if (Datos[t] > LRI && Datos[t] < LRF)
  423.                         {
  424.                             Fmr++;
  425.                         }
  426.                     }
  427.                     Fcam = Fcam + Fmr;
  428.                     double Fpr = Math.Round(Convert.ToDouble(Fmr) * 100 / Convert.ToDouble(N), 2);
  429.                     AgrupC=AgrupC+$"\n{LRI} - {LRF} | {Xmr} | {Fmr} | {Fcam} | {Fpr}";
  430.                     LRI = LRF;
  431.                 } while (LRF < Datos[N - 1]);
  432.                 marco.IsVisible=true;
  433.                 ResED.IsVisible=true;
  434.             }
  435.             catch(FormatException ex)
  436.             {
  437.                 await DisplayAlert("El entero debe ser \nmayor que 1", ex.Message,"Salir");
  438.             }
  439.         }
  440.         private void BtOrdenClick(object sender, EventArgs e)
  441.         {
  442.             orden="";
  443.             ResED.Text="";
  444.             for (int i=0; i<N; i++)
  445.             {
  446.                 if (i==N-1)
  447.                 {
  448.                     orden = orden+Datos[i];
  449.                     break;
  450.                 }
  451.                 else if(N%2==1& i==((N+1)/2)-1)
  452.                 {
  453.                     orden = orden+"→ "+Datos[i] +" ←"+", ";
  454.                     continue;
  455.                 }
  456.                 orden = orden+Datos[i] +", ";
  457.             }
  458.             ResED.Text=ResED.Text+$"\n{orden}";
  459.             marco.IsVisible=true;
  460.         }
  461.         private void BtfSimpleClick(object sender, EventArgs e)
  462.         {
  463.             ResED.Text = frec;
  464.             marco.IsVisible=true;
  465.         }
  466.         private void BtMediaClick(object sender, EventArgs e)
  467.         {
  468.             ResED.Text = ResED.Text+$"\nLa media es μ = {Media}";
  469.             marco.IsVisible=true;
  470.         }
  471.         private void BtResumClick(object sender, EventArgs e)
  472.         {
  473.             Entero.Text="";
  474.             marco.IsVisible=false;
  475.             ResED.Text=""; N=0;
  476.             frec=""; orden=""; MedText=""; MO=""; DISPERSION="";
  477.             Sesgo=""; CURTOSIS=""; Cuartiles=""; AgrupC=""; AgrupD="";
  478.         }
  479.         private void BtBorrarClick(object sender, EventArgs e)
  480.         {
  481.             marco.IsVisible=false;
  482.             ResED.Text="";
  483.         }
  484.         private void BtMedianaClick(object sender, EventArgs e)
  485.         {
  486.             ResED.Text = ResED.Text+$"\n{MedText}";
  487.             marco.IsVisible=true;
  488.         }
  489.         private void BtModaClick(object sender, EventArgs e)
  490.         {
  491.             ResED.Text = $"{MO}";
  492.             marco.IsVisible=true;
  493.         }
  494.         private void BtDispClick(object sender, EventArgs e)
  495.         {
  496.             ResED.Text = $"{DISPERSION}";
  497.             marco.IsVisible=true;
  498.         }
  499.         private void BtSesgoClick(object sender, EventArgs e)
  500.         {
  501.             ResED.Text = $"{Sesgo}";
  502.             marco.IsVisible=true;
  503.         }
  504.         private void BtCurtClick(object sender, EventArgs e)
  505.         {
  506.             ResED.Text = $"{CURTOSIS}";
  507.             marco.IsVisible=true;
  508.         }
  509.         private void BtDADClick(object sender, EventArgs e)
  510.         {
  511.             ResED.Text = $"{AgrupD}";
  512.             marco.IsVisible=true;
  513.         }
  514.         private void BtDACClick(object sender, EventArgs e)
  515.         {
  516.             ResED.Text = $"{AgrupC}";
  517.             marco.IsVisible=true;
  518.         }
  519.         private void BtCuartClick(object sende, EventArgs e)
  520.         {
  521.             if (N>=4 && Datos[0]!=Datos[N-1])  
  522.             {  
  523.                 int nd1= N+ 1;
  524.                 double Pos = 0.25*nd1; double Q1; int PQ1;
  525.                 PQ1 = Convert.ToInt32(Math.Truncate(Pos));
  526.                 Q1 = Datos[PQ1 - 1] + (Pos - PQ1) *(Datos[PQ1]-Datos[PQ1 - 1]);
  527.                 Cuartiles="CUARTIL Q1:";
  528.                 Cuartiles= Cuartiles + $"\nPosición: (N+1)/4 = {nd1}/4 = {Pos}";
  529.                 Cuartiles=Cuartiles+$"\nValor: Q1 = {Q1}; un 25% de los datos \nes menor o igual que {Q1}.";
  530.                 Cuartiles=Cuartiles+$"\n\nCUARTIL Q2 = {M} = Mediana.";
  531.                 double Pos3=0.75 * nd1; double Q3; int PQ3;
  532.                 PQ3=Convert.ToInt32(Math.Truncate(Pos3));
  533.                 Q3 = Datos[PQ3 - 1] + (Pos3 - PQ3)*(Datos[PQ3]-Datos[PQ3 - 1]);
  534.                 Cuartiles=Cuartiles+"\n\nCUARTIL Q3:";
  535.                 Cuartiles=Cuartiles+$"\nPosición: 3(N+1)/4 = 3 x {nd1}/4 = {Pos3}";
  536.                 Cuartiles=Cuartiles+$"\nValor: Q3 = {Q3}; un 75% de los datos \nes menor o igual que {Q3}.";
  537.             }
  538.             else if(N==0)
  539.             {
  540.                 Cuartiles="";
  541.             }
  542.             else
  543.             {
  544.                 Cuartiles="No es posible determinar cuartiles para \n\tN < 4 \nNi para muestras que constan de un solo valor repetido.";
  545.             }
  546.             ResED.Text=$"{Cuartiles}";
  547.             marco.IsVisible=true;
  548.         }
  549.     }
  550. }
Tags: Estadistica
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement