I Ejercicio Tamaño de la muestra para estimar la proporcion de articulos defectuosos por turno de fabricación.
(Razón de estratificación) turno de fabricación: mañana,tarde y noche.

# Se inicia con establecer una función que tenga en cuenta una serie de parámetros.Estos son:
#vector de los estratos Ni
#vector de defectusos  pi
# error del muestro (e)
#tiempo de operación en cada estrato ti
f_sam_prop = function(Ni,pi,ti,e,z=1.96 ){
  N= sum(Ni) #tamano de la poblacion 
  L=length(Ni)#Calculo el  largo del vector, este me indica cuantos estratos tengo 
  qi =1-pi #q = 1-p  proporcion de NO defectusos 
  ai=Ni/N   #pesos por estratos 
  D=(e/z)**2 #Estimación del errror 
  
  numer = sum(Ni**2*pi*qi/ai)
  denom=(N**2*D) + sum(Ni*pi*qi)
  n=ceiling(numer/denom) #Aqui se obtiene el tamaño de la muestra.
#Asignacion proporcional para decir cuantas muestras se va a cada estrato.
  ni =round(ai*n) # tamano de muestra en cada estrato
#cada cuantos minutos se va a hacer el muestreo
  ki=floor(ti/ni) # tiempo de muestreo sistemático por estrato es decir cada cuanto (unidad de tiempo:minutos) debo muestrear en cada estrato  
    return(list(ni,ki))
}

Partiendo del ejercio realizado en clase tenemos tres turnos: mañana,tarde y noche.

#Evaluacion de la función con los datos de los tres turnos
f_sam_prop(Ni=c(6000,5000,4000),
           pi=c(0.04,0.05,0.08),
           ti=c(480,480,480), #tiempo de operacion en minutos 
           e=0.05)
## [[1]]
## [1] 31 26 21
## 
## [[2]]
## [1] 15 18 22
# Para dos estratos (2 turnos: Diurno y nocturno)
#Diurno (mañana + tarde)
#Ni = 6000+5000 = 11000
#pi =
#ti=480+480=960
#Nocturno
#Ni = 4000
#pi =0.08
#ti=480

f_sam_prop(Ni = c(11000,4000),
           pi = c(0.065,0.08),
           ti=c(960,480),
           e = 0.05)
## [[1]]
## [1] 73 26
## 
## [[2]]
## [1] 13 18
#Cuando se tiene tres turno podemos evaluar la probabilidad de que el articulo defectuoso provenga de cada turno (mañana,tarde y noche)
a=2/5*0.03 +1/3*0.04+4/15*0.06
#probabilidad de provenir del turno de la manana
Pt_manana=(2/5*0.03)/a
#turno de la tarde
Pt_tarde=(1/3*0.04)/a
#turno de la noche
Pt_noche=(4/15*0.06)/a
#Ahora se evalua la probabiilidad de que el articulo provenga del turno Diurno o del nocturno
Pt_diurno =((11/5*0.035)/((11/5*0.035)+(4/15*0.06)))
Pt_diurno
## [1] 0.827957
Pt_nocturno= ((4/15*0.06)/((11/5*0.035)+(4/15*0.06)))
Pt_nocturno
## [1] 0.172043
# De acuerdo a los resultados podemos concluir que la probabilidad es mayor de que el articulo defectuoso provenga del turno diurno 

Muestreo espacial II Ejercicio:

El este ejemplo se emplea el muestreo implementado en un cultivo de palma y se emplea la libreria de hipercubo latino

# se establece la rejilla de coordenadas
palmas = expand.grid(x = seq(0, 112, 7),
                     y = seq(0, 144, 9))
set.seed(123)

# Informacion auxiliar (produccion anterior)
p_racimo_u = rnorm(289, 17, 1.8)  # peso promedio racimo de la última cosecha
p_racimo_p = rnorm(289, 17, 1.8) # peso promedio racimo de la penúltima cosecha 
CaMg_h17 = runif(289, 1.8, 2.0) # Relacion Ca/Mg hoja 17
CaMg_s = runif(289, 1.2, 1.4) # Relacion Ca/Mg suelo
hibrid = rep(c('h1','h2'), c(144, 145))

df_datosPalma = data.frame(palmas,
                p_racimo_u, p_racimo_p,
                CaMg_h17, CaMg_s, hibrid)
head(df_datosPalma)
##    x y p_racimo_u p_racimo_p CaMg_h17   CaMg_s hibrid
## 1  0 0   15.99114   17.30252 1.813162 1.350780     h1
## 2  7 0   16.58568   19.10309 1.970874 1.212619     h1
## 3 14 0   19.80567   18.89753 1.902082 1.288496     h1
## 4 21 0   17.12692   19.06147 1.842000 1.300134     h1
## 5 28 0   17.23272   15.96056 1.875169 1.254049     h1
## 6 35 0   20.08712   20.60447 1.841473 1.319760     h1
df_15palmas<-df_datosPalma
library(clhs)
library(ggplot2)
#Se estable el numero sugerido de palmas a evaluar
289*0.05 #Este resultado indica que se deben evaluar 15 palmas
## [1] 14.45
res <- clhs(df_datosPalma, size = 15, progress = FALSE, simple = TRUE)
## Warning: NAs introduced by coercion
df_datosPalma[res, 'muestreo'] = 'si'
df_datosPalma$muestreo[is.na(df_datosPalma$muestreo)]='no'
length(df_datosPalma$muestreo[df_datosPalma$muestreo == "si"])
## [1] 15
ggplot(df_datosPalma)+aes(x,y,fill=muestreo)+geom_tile(color='white')+geom_point(data=df_datosPalma,aes(shape = factor(hibrid)), size = 1.8)+labs(shape="Hibrido", fill="Muestreo")

#Estimaciones sobre los datos:
mean(df_datosPalma$p_racimo_u) #media del peso promedio racimo de la última cosecha
## [1] 17.02191
mean(df_datosPalma$p_racimo_p)#peso promedio racimo de la penúltima cosecha 
## [1] 17.09966
#Ahora de los datos muestreados 
mean(df_datosPalma$p_racimo_u[df_datosPalma$muestreo=='si'])
## [1] 16.68358
mean(df_datosPalma$p_racimo_u[df_datosPalma$muestreo=='no'])
## [1] 17.04043

Ahora se tomara un tamaño de muestra de 15

set.seed(123)
df2 <- clhs(df_15palmas, size = 15, progress = FALSE, simple = TRUE)
## Warning: NAs introduced by coercion
df_15palmas[df2,'muestreo']= 'si'
df_15palmas$muestreo[is.na(df_15palmas$muestreo)]='no'
data.frame(df_15palmas)
##       x   y p_racimo_u p_racimo_p CaMg_h17   CaMg_s hibrid muestreo
## 1     0   0   15.99114   17.30252 1.813162 1.350780     h1       no
## 2     7   0   16.58568   19.10309 1.970874 1.212619     h1       no
## 3    14   0   19.80567   18.89753 1.902082 1.288496     h1       no
## 4    21   0   17.12692   19.06147 1.842000 1.300134     h1       no
## 5    28   0   17.23272   15.96056 1.875169 1.254049     h1       no
## 6    35   0   20.08712   20.60447 1.841473 1.319760     h1       no
## 7    42   0   17.82965   17.12006 1.891848 1.347168     h1       no
## 8    49   0   14.72289   20.36033 1.848300 1.342716     h1       no
## 9    56   0   15.76366   14.56838 1.823738 1.223299     h1       si
## 10   63   0   16.19781   17.03777 1.814494 1.315024     h1       no
## 11   70   0   19.20335   19.24985 1.938198 1.359626     h1       no
## 12   77   0   17.64766   15.71256 1.857392 1.246365     h1       no
## 13   84   0   17.72139   15.64516 1.829882 1.344971     h1       no
## 14   91   0   17.19923   15.31063 1.994486 1.367605     h1       no
## 15   98   0   15.99949   15.10548 1.882103 1.223768     h1       no
## 16  105   0   20.21644   16.21311 1.880363 1.391790     h1       no
## 17  112   0   17.89613   17.59612 1.929711 1.349553     h1       no
## 18    0   9   13.46009   13.37442 1.983261 1.362178     h1       no
## 19    7   9   18.26244   17.38156 1.843332 1.237984     h1       no
## 20   14   9   16.14898   19.22602 1.909600 1.205194     h1       no
## 21   21   9   15.07792   20.66763 1.944010 1.372756     h1       no
## 22   28   9   16.60765   19.34212 1.879449 1.383836     h1       no
## 23   35   9   15.15319   18.36219 1.818800 1.227526     h1       no
## 24   42   9   15.68800   13.89189 1.926979 1.295530     h1       no
## 25   49   9   15.87493   15.91729 1.800496 1.292592     h1       no
## 26   56   9   13.96395   16.36632 1.842105 1.340036     h1       no
## 27   63   9   18.50802   18.26634 1.935805 1.213115     h1       no
## 28   70   9   17.27607   16.80979 1.973238 1.346608     h1       no
## 29   77   9   14.95135   14.73443 1.959939 1.279186     h1       no
## 30   84   9   19.25687   20.03198 1.826999 1.292298     h1       no
## 31   91   9   17.76764   18.64050 1.877500 1.345060     h1       no
## 32   98   9   16.46887   17.42737 1.957694 1.294001     h1       no
## 33  105   9   18.61123   19.19260 1.938583 1.399905     h1       no
## 34  112   9   18.58064   14.59021 1.918855 1.369187     h1       no
## 35    0  18   18.47885   18.18948 1.824772 1.365641     h1       no
## 36    7  18   18.23955   16.05876 1.911016 1.352329     h1       no
## 37   14  18   17.99705   18.23074 1.889882 1.222421     h1       no
## 38   21  18   16.88856   16.89052 1.953233 1.367795     h1       no
## 39   28  18   16.44927   18.13933 1.805220 1.362770     h1       no
## 40   35  18   16.31515   19.40393 1.839034 1.398282     h1       si
## 41   42  18   15.74953   17.01312 1.976247 1.209663     h1       no
## 42   49  18   16.62575   18.83161 1.821960 1.349358     h1       no
## 43   56  18   14.72229   14.86082 1.993710 1.283863     h1       no
## 44   63  18   20.90412   15.70111 1.877040 1.316429     h1       no
## 45   70  18   19.17433   19.73459 1.971718 1.366147     h1       no
## 46   77  18   14.97840   17.67930 1.977477 1.202706     h1       no
## 47   84  18   16.27481   13.30600 1.897818 1.202304     h1       no
## 48   91  18   16.16002   14.54473 1.943618 1.399289     h1       no
## 49   98  18   18.40394   16.63859 1.897341 1.353138     h1       no
## 50  105  18   16.84994   18.55840 1.997742 1.262933     h1       no
## 51  112  18   17.45597   16.81661 1.812950 1.362402     h1       no
## 52    0  27   16.94862   18.12354 1.831533 1.398244     h1       no
## 53    7  27   16.92283   18.72621 1.957070 1.240152     h1       no
## 54   14  27   19.46348   20.00790 1.908438 1.329207     h1       no
## 55   21  27   16.59361   17.10083 1.883309 1.287510     h1       no
## 56   28  27   19.72965   16.90643 1.999777 1.387606     h1       no
## 57   35  27   14.21224   13.84417 1.851135 1.397601     h1       no
## 58   42  27   18.05230   17.17879 1.901575 1.291264     h1       no
## 59   49  27   17.22294   15.97067 1.815794 1.246123     h1       no
## 60   56  27   17.38869   15.24678 1.962734 1.339098     h1       no
## 61   63  27   17.68335   16.67617 1.876436 1.311326     h1       no
## 62   70  27   16.09582   18.82690 1.960437 1.316942     h1       si
## 63   77  27   16.40023   13.41305 1.839585 1.286726     h1       no
## 64   84  27   15.16656   16.23090 1.989280 1.285235     h1       no
## 65   91  27   15.07078   17.20995 1.869134 1.319371     h1       no
## 66   98  27   17.54635   15.39223 1.904410 1.290417     h1       no
## 67  105  27   17.80678   17.60103 1.822338 1.391322     h1       no
## 68  112  27   17.09541   17.74057 1.977195 1.368886     h1       no
## 69    0  36   18.66008   16.94053 1.990851 1.244554     h1       no
## 70    7  36   20.69015   12.56138 1.808076 1.284034     h1       no
## 71   14  36   16.11614   21.62862 1.898723 1.283997     h1       no
## 72   21  36   12.84350   16.63046 1.845213 1.204158     h1       no
## 73   28  36   18.81033   18.17215 1.971760 1.276090     h1       no
## 74   35  36   15.72344   17.49278 1.906187 1.284470     h1       no
## 75   42  36   15.76158   18.84441 1.800928 1.238285     h1       no
## 76   49  36   18.84603   18.47179 1.855512 1.341066     h1       si
## 77   56  36   16.48741   16.62237 1.865041 1.202704     h1       no
## 78   63  36   14.80271   17.68070 1.917741 1.346241     h1       no
## 79   70  36   17.32635   15.29826 1.849937 1.286545     h1       no
## 80   77  36   16.75000   18.54246 1.808623 1.346248     h1       no
## 81   84  36   17.01038   16.17013 1.822136 1.202788     h1       no
## 82   91  36   17.69350   21.35019 1.940751 1.209063     h1       no
## 83   98  36   16.33281   14.02811 1.987804 1.283683     h1       no
## 84  105  36   18.15988   16.16482 1.862234 1.328768     h1       no
## 85  112  36   16.60312   18.48568 1.815699 1.243959     h1       no
## 86    0  45   17.59721   17.91824 1.864349 1.366689     h1       no
## 87    7  45   18.97431   15.93893 1.924981 1.338953     h1       no
## 88   14  45   17.78333   15.20579 1.888048 1.379825     h1       no
## 89   21  45   16.41332   17.26006 1.960269 1.282848     h1       no
## 90   28  45   19.06785   16.97425 1.855857 1.282201     h1       no
## 91   35  45   18.78831   13.77749 1.914143 1.250003     h1       no
## 92   42  45   17.98711   17.06219 1.808426 1.274753     h1       no
## 93   49  45   17.42972   17.34241 1.838143 1.246379     h1       no
## 94   56  45   15.86977   17.31451 1.945417 1.386321     h1       no
## 95   63  45   19.44917   15.10097 1.965338 1.295269     h1       no
## 96   70  45   15.91953   17.85704 1.902144 1.209533     h1       no
## 97   77  45   20.93720   19.48143 1.913545 1.354706     h1       no
## 98   84  45   19.75870   17.82123 1.800231 1.266223     h1       no
## 99   91  45   16.57574   14.95594 1.828756 1.310575     h1       no
## 100  98  45   15.15244   16.21584 1.973193 1.335266     h1       no
## 101 105  45   15.72127   17.62299 1.816512 1.255467     h1       no
## 102 112  45   17.46239   15.83532 1.848914 1.210571     h1       no
## 103   0  54   16.55595   13.11624 1.996309 1.285152     h1       no
## 104   7  54   16.37442   18.59165 1.915516 1.322024     h1       no
## 105  14  54   15.28709   15.50694 1.849745 1.395209     h1       no
## 106  21  54   16.91895   15.96759 1.922991 1.393960     h1       no
## 107  28  54   15.58717   19.70702 1.806351 1.217697     h1       no
## 108  35  54   13.99770   15.60654 1.829285 1.299676     h1       no
## 109  42  54   16.31559   18.52232 1.940615 1.279138     h1       no
## 110  49  54   18.65419   14.73077 1.813112 1.278066     h1       no
## 111  56  54   15.96438   16.36182 1.924361 1.263700     h1       no
## 112  63  54   18.09434   16.86760 1.987465 1.336515     h1       no
## 113  70  54   14.08781   14.89643 1.817579 1.256923     h1       no
## 114  77  54   16.89999   15.85745 1.994561 1.278019     h1       no
## 115  84  54   17.93493   16.94809 1.805202 1.398034     h1       no
## 116  91  54   17.54208   18.20725 1.945046 1.358401     h1       no
## 117  98  54   17.19022   14.02902 1.890741 1.262481     h1       no
## 118 105  54   15.84673   16.37044 1.913236 1.363424     h1       si
## 119 112  54   15.47053   18.36153 1.974546 1.244182     h1       no
## 120   0  63   15.15657   16.03014 1.910913 1.300215     h1       no
## 121   7  63   17.21176   17.40913 1.947530 1.233394     h1       no
## 122  14  63   15.29455   17.88601 1.924626 1.223932     h1       no
## 123  21  63   16.11700   17.48210 1.862206 1.379522     h1       no
## 124  28  63   16.53903   18.17586 1.878439 1.218743     h1       si
## 125  35  63   20.31895   16.77912 1.840417 1.373012     h1       no
## 126  42  63   15.82649   16.25538 1.970556 1.255318     h1       no
## 127  49  63   17.42370   12.24233 1.921366 1.205457     h1       no
## 128  56  63   17.14033   16.83271 1.951220 1.357477     h1       no
## 129  63  63   15.26866   17.77451 1.912503 1.271732     h1       no
## 130  70  63   16.87165   17.96372 1.855180 1.205021     h1       no
## 131  77  63   19.60019   16.00050 1.947112 1.349219     h1       no
## 132  84  63   17.81271   20.20311 1.909856 1.205925     h1       no
## 133  91  63   17.07422   17.51556 1.869225 1.286773     h1       no
## 134  98  63   16.23951   17.22737 1.902993 1.251325     h1       no
## 135 105  63   13.30416   19.29008 1.963154 1.299603     h1       no
## 136 112  63   19.03641   15.70676 1.905255 1.330671     h1       no
## 137   0  72   14.37085   16.18939 1.840608 1.216731     h1       no
## 138   7  72   18.33191   21.31541 1.969622 1.236094     h1       no
## 139  14  72   20.43639   17.02003 1.874099 1.220893     h1       no
## 140  21  72   14.40099   19.94042 1.860665 1.362479     h1       no
## 141  28  72   18.26321   14.41069 1.954119 1.325500     h1       no
## 142  35  72   16.52804   16.65707 1.946690 1.326114     h1       no
## 143  42  72   14.17014   17.68116 1.967781 1.278178     h1       si
## 144  49  72   14.27360   17.54007 1.913810 1.286451     h1       no
## 145  56  72   14.11723   15.18985 1.805256 1.269727     h2       no
## 146  63  72   16.04437   17.03467 1.897225 1.358712     h2       no
## 147  70  72   14.36884   15.06064 1.908536 1.377387     h2       no
## 148  77  72   18.23825   18.28287 1.967332 1.330225     h2       no
## 149  84  72   20.78020   18.95260 1.945733 1.318573     h2       no
## 150  91  72   14.68335   12.99502 1.911023 1.265564     h2       no
## 151  98  72   18.41793   19.22425 1.814683 1.215138     h2       no
## 152 105  72   18.38428   14.76612 1.827300 1.318277     h2       no
## 153 112  72   17.59796   17.81858 1.936922 1.235667     h2       no
## 154   0  81   15.18492   18.18782 1.819924 1.348270     h2       no
## 155   7  81   16.78499   16.64020 1.840757 1.258775     h2       no
## 156  14  81   16.49529   15.83879 1.873196 1.327837     h2       no
## 157  21  81   18.01338   17.29758 1.969239 1.224964     h2       no
## 158  28  81   16.32961   17.78987 1.847375 1.251053     h2       no
## 159  35  81   18.75855   18.58995 1.940976 1.364115     h2       no
## 160  42  81   16.32575   13.30579 1.821522 1.360756     h2       no
## 161  49  81   18.89488   14.05452 1.955814 1.209167     h2       no
## 162  56  81   15.11148   19.57472 1.851021 1.375106     h2       no
## 163  63  81   14.73172   18.88393 1.909609 1.225602     h2       no
## 164  70  81   22.83387   17.78352 1.806780 1.321766     h2       no
## 165  77  81   16.24966   18.28732 1.961222 1.293913     h2       no
## 166  84  81   17.53681   18.65091 1.867551 1.311458     h2       no
## 167  91  81   18.14583   12.21034 1.983257 1.346079     h2       no
## 168  98  81   16.12919   18.99850 1.871421 1.293972     h2       no
## 169 105  81   17.93035   16.12702 1.995073 1.397722     h2       no
## 170 112  81   17.66414   17.41511 1.876876 1.396934     h2       no
## 171   0  90   16.61232   16.46872 1.897735 1.278657     h2       no
## 172   7  90   17.11753   18.56954 1.898155 1.321769     h2       no
## 173  14  90   16.93868   16.37275 1.802451 1.269097     h2       no
## 174  21  90   20.83121   17.93331 1.928295 1.287423     h2       no
## 175  28  90   15.66560   16.29677 1.902515 1.245826     h2       no
## 176  35  90   15.02721   15.03298 1.864070 1.201214     h2       no
## 177  42  90   17.06802   19.17802 1.916287 1.204775     h2       no
## 178  49  90   17.55887   18.33362 1.923469 1.211752     h2       no
## 179  56  90   17.78574   20.10367 1.887655 1.352915     h2       no
## 180  63  90   16.17494   17.11728 1.834074 1.293809     h2       no
## 181  70  90   15.08601   19.02500 1.943016 1.370166     h2       no
## 182  77  90   19.27373   20.55575 1.949557 1.316344     h2       no
## 183  84  90   16.37063   16.49333 1.968783 1.237378     h2       no
## 184  91  90   15.44208   14.61869 1.906952 1.321812     h2       no
## 185  98  90   16.57470   16.56917 1.860447 1.378668     h2       no
## 186 105  90   16.64508   16.61473 1.891304 1.358864     h2       no
## 187 112  90   18.99786   17.27302 1.876869 1.300819     h2       si
## 188   0  99   17.15253   20.08215 1.849809 1.284606     h2       no
## 189   7  99   18.35730   16.41294 1.930925 1.330876     h2       no
## 190  14  99   16.10127   17.67141 1.991065 1.377548     h2       no
## 191  21  99   17.38600   16.59017 1.858217 1.378403     h2       no
## 192  28  99   16.41557   17.03681 1.930038 1.235678     h2       no
## 193  35  99   17.17025   17.56530 1.907272 1.251500     h2       no
## 194  42  99   15.38835   19.39079 1.919490 1.222688     h2       no
## 195  49  99   14.64056   17.21837 1.804980 1.359432     h2       no
## 196  56  99   20.59498   18.28312 1.800968 1.221908     h2       no
## 197  63  99   18.08128   18.40195 1.826276 1.365814     h2       no
## 198  70  99   14.74771   18.64659 1.804963 1.354209     h2       no
## 199  77  99   15.89990   15.96609 1.818426 1.388738     h2       no
## 200  84  99   14.86614   19.92839 1.895112 1.293392     h2       si
## 201  91  99   20.95786   16.31428 1.839331 1.387971     h2       no
## 202  98  99   19.36234   16.80959 1.962935 1.357037     h2       no
## 203 105  99   16.52274   19.52729 1.848812 1.374922     h2       no
## 204 112  99   17.97775   19.32935 1.897762 1.278893     h2       no
## 205   0 108   16.25419   15.03801 1.929776 1.219940     h2       no
## 206   7 108   16.14276   15.42847 1.831743 1.255392     h2       no
## 207  14 108   15.58051   14.55546 1.967396 1.344444     h2       no
## 208  21 108   15.92969   17.32732 1.887319 1.271261     h2       no
## 209  28 108   19.97163   17.29671 1.846699 1.276542     h2       no
## 210  35 108   16.90275   17.65541 1.859771 1.206394     h2       no
## 211  42 108   17.21464   17.99388 1.831884 1.304289     h2       no
## 212  49 108   17.43864   15.91659 1.917113 1.224216     h2       no
## 213  56 108   19.21846   15.21134 1.829756 1.377037     h2       no
## 214  63 108   16.07109   18.84821 1.835812 1.214929     h2       no
## 215  70 108   15.21349   18.35191 1.867844 1.356846     h2       no
## 216  77 108   20.01625   14.28350 1.836780 1.370826     h2       no
## 217  84 108   16.20591   16.82873 1.881108 1.207436     h2       no
## 218  91 108   15.69848   15.38729 1.922712 1.255029     h2       si
## 219  98 108   14.77471   13.27265 1.937134 1.328414     h2       no
## 220 105 108   14.68751   17.27022 1.964705 1.357016     h2       no
## 221 112 108   15.96685   16.85742 1.874796 1.280013     h2       no
## 222   0 117   18.11237   16.82474 1.990568 1.387060     h2       si
## 223   7 117   18.99773   17.38907 1.803766 1.278103     h2       no
## 224  14 117   18.27366   18.58844 1.922475 1.284792     h2       no
## 225  21 117   16.34542   17.37008 1.892715 1.257284     h2       no
## 226  28 117   17.10755   15.89042 1.870946 1.322350     h2       no
## 227  35 117   15.73173   15.67736 1.976485 1.311763     h2       no
## 228  42 117   15.70901   16.76275 1.815161 1.207993     h2       no
## 229  49 117   18.59237   17.55803 1.976658 1.349056     h2       no
## 230  56 117   15.17193   15.12858 1.837644 1.241297     h2       no
## 231  63 117   20.51953   16.66824 1.843013 1.331299     h2       no
## 232  70 117   16.83742   18.74108 1.973906 1.304483     h2       no
## 233  77 117   17.38617   16.80510 1.812168 1.326687     h2       si
## 234  84 117   15.67065   15.74284 1.846980 1.323513     h2       no
## 235  91 117   15.96610   16.50330 1.998603 1.256979     h2       no
## 236  98 117   14.62937   19.00637 1.935640 1.244761     h2       no
## 237 105 117   16.67073   17.99008 1.887097 1.307804     h2       no
## 238 112 117   17.75417   19.22602 1.875462 1.399274     h2       no
## 239   0 126   17.58375   17.25038 1.892237 1.265783     h2       no
## 240   7 126   15.59323   17.73850 1.960370 1.264667     h2       no
## 241  14 126   15.58048   15.99478 1.932593 1.207065     h2       si
## 242  21 126   16.09604   18.08967 1.893201 1.305122     h2       no
## 243  28 126   19.69291   16.08860 1.810652 1.319361     h2       no
## 244  35 126   14.95285   14.44298 1.847440 1.348417     h2       no
## 245  42 126   16.67771   17.23039 1.846648 1.390567     h2       no
## 246  49 126   20.42425   20.50253 1.846131 1.297924     h2       no
## 247  56 126   16.81825   18.44165 1.812345 1.216657     h2       no
## 248  63 126   14.55229   19.09746 1.899424 1.251986     h2       no
## 249  70 126   15.80342   17.64594 1.848825 1.374969     h2       no
## 250  77 126   17.87383   15.90460 1.951637 1.370412     h2       no
## 251  84 126   16.32391   16.63597 1.909461 1.368581     h2       no
## 252  91 126   15.98862   16.50815 1.989613 1.389381     h2       no
## 253  98 126   16.38095   16.15634 1.817234 1.330536     h2       no
## 254 105 126   17.16289   18.26750 1.989577 1.297631     h2       no
## 255 112 126   19.87732   14.84475 1.944480 1.237551     h2       no
## 256   0 135   16.84058   18.55946 1.984401 1.342607     h2       no
## 257   7 135   18.94544   18.55547 1.922768 1.217014     h2       no
## 258  14 135   18.13536   14.84248 1.832193 1.292240     h2       no
## 259  21 135   16.79545   18.15109 1.836588 1.387181     h2       no
## 260  28 135   14.24078   21.37441 1.946037 1.369059     h2       no
## 261  35 135   16.06199   15.99701 1.917905 1.343237     h2       no
## 262  42 135   16.11823   18.52083 1.862496 1.224761     h2       no
## 263  49 135   17.08488   15.59204 1.954559 1.318965     h2       no
## 264  56 135   19.34036   18.99928 1.867260 1.397971     h2       no
## 265  63 135   21.12754   17.44968 1.971135 1.323082     h2       si
## 266  70 135   19.78565   19.97345 1.916106 1.254616     h2       no
## 267  77 135   16.76033   14.37385 1.883145 1.212741     h2       no
## 268  84 135   13.83825   16.90766 1.986515 1.214461     h2       no
## 269  91 135   16.30020   16.05153 1.892540 1.374702     h2       no
## 270  98 135   17.16057   16.64492 1.819869 1.272565     h2       si
## 271 105 135   18.52102   15.86676 1.893090 1.389124     h2       no
## 272 112 135   18.73255   15.49908 1.996817 1.311664     h2       no
## 273   0 144   18.23176   18.04170 1.985055 1.302532     h2       no
## 274   7 144   14.48851   15.04235 1.887080 1.389554     h2       no
## 275  14 144   18.52936   19.67126 1.973944 1.221960     h2       no
## 276  21 144   16.19620   14.86483 1.860071 1.363782     h2       no
## 277  28 144   17.31464   17.18194 1.959595 1.275468     h2       no
## 278  35 144   17.13419   17.95938 1.960102 1.311328     h2       no
## 279  42 144   17.77070   18.05612 1.877385 1.262774     h2       no
## 280  49 144   17.04441   16.45686 1.876318 1.216469     h2       no
## 281  56 144   13.99854   17.14310 1.929103 1.355988     h2       no
## 282  63 144   18.32569   18.73028 1.972333 1.238647     h2       no
## 283  70 144   17.69485   14.37836 1.931327 1.331117     h2       no
## 284  77 144   16.52183   15.59287 1.903265 1.287029     h2       no
## 285  84 144   17.21266   17.57672 1.829756 1.239430     h2       no
## 286  91 144   17.24127   16.19939 1.922553 1.398932     h2       no
## 287  98 144   17.39784   19.46601 1.808393 1.289349     h2       no
## 288 105 144   19.95352   18.21186 1.899672 1.206285     h2       no
## 289 112 144   16.60571   17.12990 1.947902 1.387403     h2       no
length(df_15palmas$muestreo[df_15palmas$muestreo == "si"])
## [1] 15
length(df2)
## [1] 15
library(ggplot2)
ggplot(df_15palmas)+ aes(x,y,fill=muestreo)+ geom_tile(color='white')+ geom_point(data=df_15palmas,aes(shape = factor(hibrid)), size = 1.8)+labs(shape="Hibrido", fill="Muestreo")

mean(df_15palmas$p_racimo_u)
## [1] 17.02191
mean(df_15palmas$p_racimo_p)
## [1] 17.09966
#datos muestreados
mean(df_15palmas$p_racimo_u[df_15palmas$muestreo=='si'])
## [1] 16.83375
mean(df_15palmas$p_racimo_p[df_15palmas$muestreo=='no'])
## [1] 17.08757
#datos inciales por hibrido
mean(df_15palmas$p_racimo_u[df_15palmas$hibrido =='h1'])
## [1] NaN
mean(df_15palmas$p_racimo_pe[df_15palmas$hibrido =='h2'])
## Warning in mean.default(df_15palmas$p_racimo_pe[df_15palmas$hibrido == "h2"]):
## argument is not numeric or logical: returning NA
## [1] NA
#datos muestreados por hibrido
mean(df_15palmas$p_racimo_u[df_15palmas$muestreo=='si' & df_15palmas$hibrid=='h1'])
## [1] 16.22522
mean(df_15palmas$p_racimo_u[df_15palmas$muestreo=='si' & df_15palmas$hibrid=='h2'])
## [1] 17.3662