Se omiten las tildes y caracteres, por cuestiones de edicion.
43+7
## [1] 50
76-43
## [1] 33
(12 + 52) * 3
## [1] 192
a<- 33
1:10
## [1] 1 2 3 4 5 6 7 8 9 10
seq(1, 29, by=2)
## [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
seq(from = 1, to = 15, by = 2)
## [1] 1 3 5 7 9 11 13 15
seq(1,100,4)
## [1] 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81 85 89
## [24] 93 97
c(0, 3, 6, 7, 9, 12)
## [1] 0 3 6 7 9 12
#Asi mismo, podemos asignar un vector a la concatenacion.
x<- c(0, 3, 6, 7, 9, 12) # ahora x es un vector de 6 elementos
w<- c(10, 13, 26, 37, 39, 42) # ahora w es un vector de 10 elementos
w
## [1] 10 13 26 37 39 42
vector1 <-c(1,2,3,4,5)
vector2 <-c(6,7,8,9,10)
set.seed(12345)
datos1<-rnorm(30, 15, 3.5)
dat1<-round(datos1,0)
dat1
## [1] 17 17 15 13 17 9 17 14 14 12 15 21 16 17 12 18 12 14 19 16 18 20 13
## [24] 10 9 21 13 17 17 14
Se requiere instalar paquete “fdth”
library(fdth)
##
## Attaching package: 'fdth'
##
## The following objects are masked from 'package:stats':
##
## sd, var
dist<-fdt(dat1)
dist
## Class limits f rf rf(%) cf cf(%)
## [8.9,11) 3 0.1 10 3 10
## [11,13) 6 0.2 20 9 30
## [13,15) 6 0.2 20 15 50
## [15,17) 9 0.3 30 24 80
## [17,19) 3 0.1 10 27 90
## [19,21) 3 0.1 10 30 100
hist(x,breaks="Sturges")
Analice cada una de las formas
par(mfrow=c(3,3))
plot(dist, type='fh') # Absolut frequency histogram
plot(dist, type='rfh') # Relative frequency histogram
plot(dist, type='rfph') # Relative frequency (%) histogram
plot(dist, type='cdh') # Cumulative density histogram
plot(dist, type='cfh') # Cumulative frequency histogram
plot(dist, type='cfph') # Cumulative frequency (%) histogram
par(mfrow=c(3,3))
plot(dist, type='fp') # Absolut frequency poligon
plot(dist, type='rfp') # Relative frequency poligon
plot(dist, type='rfpp') # Relative frequency (%) poligon
plot(dist, type='cdp') # Cumulative density poligon
plot(dist, type='cfp') # Cumulative frequency poligon
plot(dist, type='cfpp') # Cumulative frequency (%) poligon
a<-rnorm(100, 25,5)
sort(a)
## [1] 13.09821 13.26528 14.38225 15.77316 15.83811 16.68975 17.93451
## [8] 18.28734 18.37622 18.37971 18.46601 18.52164 18.84914 19.01984
## [15] 19.20589 19.21888 19.69867 19.75324 20.09684 20.18049 20.72459
## [22] 20.94230 21.07675 21.52727 21.64512 22.00101 22.06560 22.29807
## [29] 22.31976 22.47455 22.47478 22.75983 22.89380 23.04090 23.37957
## [36] 23.44197 23.46023 23.47815 24.59623 24.65491 24.73923 25.12901
## [43] 25.26795 25.27308 25.70542 25.74796 26.11963 26.27136 26.38977
## [50] 26.60562 26.61076 26.75831 27.11209 27.38124 27.45594 27.58427
## [57] 27.68262 27.76652 27.83702 27.91594 28.14430 28.22692 28.36021
## [64] 28.43666 28.45586 29.05937 29.11898 29.12435 29.13129 29.27226
## [71] 29.44070 29.68570 29.71300 29.85610 30.10629 30.21572 30.64255
## [78] 30.78663 31.30621 31.59616 31.60726 32.01353 32.30365 32.65478
## [85] 32.72432 32.78055 32.94981 32.96744 33.16223 33.83867 34.33550
## [92] 34.43473 34.73846 35.24595 35.72533 35.78860 35.90001 35.98417
## [99] 36.65256 37.38555
sum(a) # suma
## [1] 2611.517
min(a) # valor minimo
## [1] 13.09821
max(a) # valor maximo
## [1] 37.38555
range(a) # rango
## [1] 13.09821 37.38555
mean(a) # promedio
## [1] 26.11517
median(a) # mediana
## [1] 26.60819
length(a) # cantidad de datos
## [1] 100
sd(a) # desviacion estandar
## [1] 5.851567
var(a) # varianza
## [1] 34.24083
quantile(a) #cuantil
## 0% 25% 50% 75% 100%
## 13.09821 21.91204 26.60819 30.13365 37.38555
quantile(a,.25) #devuelve el percentil 25.
## 25%
## 21.91204
IQR(a) #Valor intercartilico
## [1] 8.22161
round(a) #redondear
## [1] 29 36 35 33 26 27 23 17 34 25 31 13 20 30 29 32 18 28 28 18 22 35 25
## [24] 27 22 26 28 29 36 13 26 18 28 33 22 16 29 33 28 19 25 21 20 37 32 30
## [47] 29 21 27 30 28 30 23 37 30 34 28 23 28 29 20 21 34 23 20 28 22 36 22
## [70] 22 26 19 27 18 26 22 23 33 23 27 19 18 31 32 25 22 25 28 36 25 33 32
## [93] 27 33 23 19 16 31 14 19
b<-c(7,5,7,6,8,6,5,4,3,2,3,4,5,6,8,8,6,5,4,3,2,1,3,54,6,7,12,14,15,16,15,14,15,16,18,19,19)
sort(b) #ordenar
## [1] 1 2 2 3 3 3 3 4 4 4 5 5 5 5 6 6 6 6 6 7 7 7 8
## [24] 8 8 12 14 14 15 15 15 16 16 18 19 19 54
stem(b) #tallos y hojas
##
## The decimal point is 1 digit(s) to the right of the |
##
## 0 | 1223333444555566666777888
## 1 | 24455566899
## 2 |
## 3 |
## 4 |
## 5 | 4
hist(b) #Histograma
boxplot(b) #Diagrama de cajas
library(PASWR)
## Loading required package: e1071
## Loading required package: MASS
## Loading required package: lattice
EDA(b) #analice todos los resultantes
## [1] "b"
## Size (n) Missing Minimum 1st Qu Mean Median TrMean 3rd Qu
## 37.000 0.000 1.000 4.000 9.486 6.000 8.457 14.500
## Max. Stdev. Var. SE Mean I.Q.R. Range Kurtosis Skewness
## 54.000 9.230 85.201 1.517 10.500 53.000 11.814 3.029
## SW p-val
## 0.000
set.seed(12345)
d<-rnorm(50,25,7)
d
## [1] 29.098702 29.966262 24.234877 21.825520 29.241212 12.274308 29.410690
## [8] 23.066711 23.010882 18.564746 24.186265 37.721184 27.594395 28.641515
## [15] 19.746276 30.718299 18.795497 22.678957 32.844989 27.091066 30.457353
## [22] 35.190496 20.489701 14.128038 13.816033 37.635683 21.628468 29.342659
## [29] 29.284864 23.863823 30.683112 40.377835 39.344332 36.427119 26.779898
## [36] 28.438318 22.731394 13.365648 37.374137 25.180607 32.899576 8.337494
## [43] 17.578141 31.559984 30.981162 35.225106 15.108309 28.971823 29.082314
## [50] 15.852408
shapiro.test(d)
##
## Shapiro-Wilk normality test
##
## data: d
## W = 0.97666, p-value = 0.4211
qqnorm(d)
qqline(d)
Se conoce que el peso de las aranas adultas hembras en promedio es de 0.58 g con una desviacion estandar de 0.03. Se colecto un total de 45 ara??as. Genere los datos suponiendo una distribucion normal aleatoria los datos y responda.
Cuanto es el peso promedio de las aranas?
set.seed(12345)
ara<-rnorm(45, .58, 0.03)
mean(ara)
## [1] 0.5860579
Cuantas aranas tengo que pesan entre 0.45 y 0.52?
set.seed(12345)
ara<-rnorm(45, .58, 0.03)
pesoara<-fdt(ara, start = .45, end = .52)
pesoara
## Class limits f rf rf(%) cf cf(%)
## [0.45,0.464) 0 0.00 0.00 0 0.00
## [0.464,0.478) 0 0.00 0.00 0 0.00
## [0.478,0.492) 0 0.00 0.00 0 0.00
## [0.492,0.506) 0 0.00 0.00 0 0.00
## [0.506,0.52) 1 0.02 2.22 1 2.22
Cuanto es el 25% del peso de las aranas?
set.seed(12345)
ara<-rnorm(45, .58, 0.03)
quantile(ara,.25)
## 25%
## 0.5663951
Es posible determinar que el peso de la muestra es mayor a 0.58?
set.seed(12345)
ara<-rnorm(45, .58, 0.03)
shapiro.test(ara)
##
## Shapiro-Wilk normality test
##
## data: ara
## W = 0.97879, p-value = 0.5714
t.test(ara, mu=.58, alternative = "g")
##
## One Sample t-test
##
## data: ara
## t = 1.2437, df = 44, p-value = 0.1101
## alternative hypothesis: true mean is greater than 0.58
## 95 percent confidence interval:
## 0.5778735 Inf
## sample estimates:
## mean of x
## 0.5860579
Genere un diagrama de cajas del peso de las aranas.?
boxplot(ara, col="springgreen")
Se tomaron datos de una segunda poblacion que esta separada por aprox. 100 km. Los datos del peso se resumen en: rnorm(52, 0.47,0.17)
Es posible que es peso de las aranas de la P1, sea dif de la Pob2.?
set.seed(12345)
ara2<-rnorm(52, 0.47,0.17)
ara2
## [1] 0.56953990 0.59060922 0.45141844 0.39290548 0.57300087 0.16094749
## [7] 0.57711675 0.42304870 0.42169284 0.31371526 0.45023787 0.77894305
## [13] 0.53300674 0.55843680 0.34240956 0.60887297 0.31931922 0.41363181
## [19] 0.66052115 0.52078303 0.60253573 0.71748346 0.36046417 0.20596664
## [25] 0.19838938 0.77686658 0.38811995 0.57546457 0.57406099 0.44240713
## [31] 0.60801844 0.84346170 0.81836236 0.74751576 0.51322610 0.55350201
## [37] 0.41490528 0.18745146 0.77051475 0.47438618 0.66184684 0.06533913
## [43] 0.28975486 0.62931389 0.61525679 0.71832400 0.22977321 0.56645855
## [49] 0.56914190 0.24784420 0.37813437 0.80110775
shapiro.test(ara2)
##
## Shapiro-Wilk normality test
##
## data: ara2
## W = 0.97733, p-value = 0.4196
var.test(ara,ara2) #Homogeneidad de las varianzas
##
## F test to compare two variances
##
## data: ara and ara2
## F = 0.030125, num df = 44, denom df = 51, p-value < 2.2e-16
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.01701814 0.05399217
## sample estimates:
## ratio of variances
## 0.0301251
t.test(ara,ara2, var.equal = FALSE)
##
## Welch Two Sample t-test
##
## data: ara and ara2
## t = 3.0916, df = 54.536, p-value = 0.003135
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.02887168 0.13533820
## sample estimates:
## mean of x mean of y
## 0.5860579 0.5039530
#Dos poblaciones
rnorm(50, 27, 7)-> d2
#test pareado
t.test(d, d2, paired = T)
##
## Paired t-test
##
## data: d and d2
## t = -1.954, df = 49, p-value = 0.05642
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -5.25623242 0.07365531
## sample estimates:
## mean of the differences
## -2.591289
#Muestras independientes
t.test(d, d2, paired = F)
##
## Welch Two Sample t-test
##
## data: d and d2
## t = -1.6641, df = 97.923, p-value = 0.09928
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -5.6814289 0.4988518
## sample estimates:
## mean of x mean of y
## 26.25696 28.84825
#Homogeneidad de Var
var.test(d, d2)
##
## F test to compare two variances
##
## data: d and d2
## F = 0.94559, num df = 49, denom df = 49, p-value = 0.8455
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.5365998 1.6663077
## sample estimates:
## ratio of variances
## 0.9455899
#Suponiendo var desiguales
t.test(d, d2, var.equal=F)
##
## Welch Two Sample t-test
##
## data: d and d2
## t = -1.6641, df = 97.923, p-value = 0.09928
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -5.6814289 0.4988518
## sample estimates:
## mean of x mean of y
## 26.25696 28.84825
#Suponiendo var iguales
t.test(d, d2, var.equal=T)
##
## Two Sample t-test
##
## data: d and d2
## t = -1.6641, df = 98, p-value = 0.09928
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -5.6813987 0.4988216
## sample estimates:
## mean of x mean of y
## 26.25696 28.84825
#revisar el help de t.test
boxplot(d, d2, col=c("gray", "grey34"))
ks.test(d, d2)
##
## Two-sample Kolmogorov-Smirnov test
##
## data: d and d2
## D = 0.22, p-value = 0.1786
## alternative hypothesis: two-sided
Se midio cantidad de una sp que se considera indicadorra, en tres sitios diferentes.
sp<-c(15,19, 22)
chisq.test(sp)
##
## Chi-squared test for given probabilities
##
## data: sp
## X-squared = 1.3214, df = 2, p-value = 0.5165
qchisq(0.95,2)
## [1] 5.991465
chisq.test(sp)$expected
## [1] 18.66667 18.66667 18.66667
sp<-c(15,19, 22)
sp2<-c(3,12,5)
habt<-data.frame(sp,sp2)
habt
## sp sp2
## 1 15 3
## 2 19 12
## 3 22 5
rownames(habt)<-c("machos","hembras", "no_sexados")
habt
## sp sp2
## machos 15 3
## hembras 19 12
## no_sexados 22 5
chisq.test(habt)
## Warning in chisq.test(habt): Chi-squared approximation may be incorrect
##
## Pearson's Chi-squared test
##
## data: habt
## X-squared = 4.1666, df = 2, p-value = 0.1245
fisher.test(habt,simulate.p.value=TRUE)
##
## Fisher's Exact Test for Count Data with simulated p-value (based
## on 2000 replicates)
##
## data: habt
## p-value = 0.1339
## alternative hypothesis: two.sided
mosaicplot(habt, color=TRUE, main="Plot de mosaico")
prop.table(habt)
## sp sp2
## machos 0.1973684 0.03947368
## hembras 0.2500000 0.15789474
## no_sexados 0.2894737 0.06578947
chisq.test(c(28,49,27), p=c(1/4,2/4,1/4))
##
## Chi-squared test for given probabilities
##
## data: c(28, 49, 27)
## X-squared = 0.36538, df = 2, p-value = 0.833
pro<-chisq.test(c(28,49,27), p=c(1/4,2/4,1/4)); pro
##
## Chi-squared test for given probabilities
##
## data: c(28, 49, 27)
## X-squared = 0.36538, df = 2, p-value = 0.833
pro$expected
## [1] 26 52 26
Desaroolle por problema del libro de Daniel. 2.3.3