##1° punto ###
library(MASS)
library(UsingR)
## Loading required package: HistData
## Loading required package: Hmisc
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
View(brightness)
library(ggplot2)
library(HistData)
## 2.2. a HIstograma y superimposed density plot##
data("brightness")
hist(brightness, freq = F)

density(brightness)
## 
## Call:
##  density.default(x = brightness)
## 
## Data: brightness (966 obs.); Bandwidth 'bw' = 0.2425
## 
##        x                y            
##  Min.   : 1.342   Min.   :0.0000156  
##  1st Qu.: 4.296   1st Qu.:0.0025868  
##  Median : 7.250   Median :0.0226027  
##  Mean   : 7.250   Mean   :0.0845551  
##  3rd Qu.:10.204   3rd Qu.:0.1267748  
##  Max.   :13.158   Max.   :0.3961890
plot(density(brightness))

hist(brightness, freq = F)
lines(density(brightness))

## 2.2. b Boxplot## LA data presenta Outliers.
#El segundo outlier más pequeño es 2.28
boxplot(brightness)

boxplot.stats(brightness)$out
##  [1] 12.31 11.71  5.53 11.28  4.78  5.13  4.37  5.04 12.43 12.04  4.55 11.55
## [13] 12.14 11.63  4.99 11.67  4.61 11.99 12.04  5.55 12.17 11.55 11.79 12.19
## [25]  2.07 11.65 11.73  2.28  5.42  3.88  5.54  5.29  5.01 11.55  4.89 11.80
## [37]  5.41  5.24
sort(boxplot.stats(brightness)$out)
##  [1]  2.07  2.28  3.88  4.37  4.55  4.61  4.78  4.89  4.99  5.01  5.04  5.13
## [13]  5.24  5.29  5.41  5.42  5.53  5.54  5.55 11.28 11.55 11.55 11.55 11.63
## [25] 11.65 11.67 11.71 11.73 11.79 11.80 11.99 12.04 12.04 12.14 12.17 12.19
## [37] 12.31 12.43
segundomenoroutlier = sort(boxplot.stats(brightness)$out)[2]
segundomenoroutlier
## [1] 2.28
## 2.2. c Crear variable sin outliers
obtener_outliers = which(brightness %in% c(boxplot.stats(brightness)$out))
obtener_outliers
##  [1]   6  17 107 111 122 145 154 183 191 263 300 307 320 353 355 390 441 454 463
## [20] 475 522 548 560 569 676 730 736 744 759 763 811 812 839 896 908 909 928 948
#Defino la nueva variable brightness.without#
brightness.without = brightness[-c(obtener_outliers)]
brightness.without
##   [1]  9.10  9.27  6.61  8.06  8.55  9.64  9.05  8.59  8.59  7.34  8.43  8.80
##  [13]  7.25  8.60  8.15 11.03  6.53  8.51  7.55  8.69  7.57  9.05  6.28  9.13
##  [25]  9.32  8.83  9.14  8.26  7.63  9.09  8.10  6.43  9.07  7.68 10.44  8.65
##  [37]  7.46  8.70 10.61  8.20  6.18  7.91  9.59  8.57 10.78  7.31  9.53  6.49
##  [49]  8.94  8.56 10.96 10.57  7.40  8.12  8.27  7.05  9.09  8.34  8.86  8.27
##  [61]  6.36  8.08 11.00  8.55  7.83  8.79  8.33 10.42  8.26  8.97  6.90  9.93
##  [73]  7.42  9.03  8.41  8.06  8.69  8.40  8.57  9.50  8.85  9.61 10.62  8.05
##  [85]  7.80  5.71  7.87  7.64  7.66  8.68  8.12 10.10  8.67 10.46  9.87  9.48
##  [97]  7.04  8.44  9.88  7.05  8.29  9.34  7.73  6.22  8.53  7.23  8.61 10.76
## [109]  8.93  7.95  7.46  8.60  8.55  9.20  6.82  8.29  6.83  7.21  5.58  8.70
## [121]  8.06 10.86  6.50  9.32  9.14  8.13 10.62  6.62  9.96  8.64  6.60  6.25
## [133]  7.83 10.03  9.04  8.47  7.33  8.66 10.35  8.96  8.49 11.26  8.15  7.04
## [145] 10.02  8.90  7.78  9.93  8.60  8.51  7.09  6.93  8.68  8.98  9.84  8.98
## [157]  7.98 10.16  8.86  8.58  9.56  9.24  9.63  5.80  9.05  8.45  8.86  7.84
## [169]  8.86  8.93  7.97  6.90  8.47  6.77  8.55  8.48  8.53  6.33  8.99  8.64
## [181]  9.55  8.74  8.16  9.46  5.70  7.62  8.95  8.97  8.94  7.24 10.32  8.24
## [193]  8.62  9.18  8.53  8.54  8.56  9.41  5.87  7.20  9.05  9.52 10.24  7.70
## [205]  8.17  7.29  9.26  7.94  8.42  8.56  7.52  7.74  8.85  9.01  7.17  9.04
## [217] 10.30  9.86  7.64  8.27  8.44  9.58  8.43  8.49  9.64  9.17  8.09  9.00
## [229]  6.25  8.56 10.81  8.76  7.76  7.82  7.90  8.52  9.73  9.19  8.10  8.75
## [241]  8.14  8.65 10.30  6.46  6.73  7.96  9.53  8.87  6.59  8.65  9.64  9.15
## [253]  9.04  8.42  8.09  9.06  8.09  8.18  8.77  7.36  9.16  8.82 11.14  6.24
## [265]  9.44  7.49  6.96  7.94  8.69  8.15  8.45  7.92  7.45  9.01  8.55  9.23
## [277]  9.16  7.90  8.68  7.78  8.21  8.11  8.29  7.89  9.67  8.24  6.80  8.18
## [289]  8.44  7.45  6.31  8.15  8.27  7.66  8.59  7.09  8.54  9.58  8.44  8.59
## [301]  8.01  8.29  9.62  7.26  7.91  9.45  8.19  8.93  7.65  8.53  7.38  8.56
## [313]  8.76  9.56  7.09  9.83  5.90 10.80  8.41  9.05  8.79  8.88  7.59  9.60
## [325] 10.66  8.55  8.11  9.44  9.60  5.78 10.66  6.38  8.80  7.79  8.60  7.77
## [337] 10.37  9.80 10.42  9.22  8.43  7.33  8.93  9.09  9.26  8.73  9.18  8.12
## [349]  9.26  8.94  6.11  9.13  7.90  9.34  7.13 10.82  7.46  8.72  7.02  9.08
## [361]  8.37  5.59  7.37  5.68  8.56  8.72  9.06  8.82  8.18  9.39  9.10  8.46
## [373]  9.15  8.28  8.18  7.93  9.21  6.09  8.31  7.83  8.72  6.61  6.25  7.82
## [385]  8.66  8.15  8.97  8.15  7.47  8.63  8.13  8.23  8.41  6.47  9.83  8.64
## [397]  7.73  8.64  8.94  8.84  6.32  5.80  8.97  7.53  7.41  7.80  8.14  6.71
## [409]  8.73  9.37  8.69  9.95  7.10  8.09  6.88  9.48  9.04  9.30  8.49  8.30
## [421]  7.95  7.08  6.93  8.38  8.56  8.78  7.42  8.26  7.71  6.91  9.16  8.99
## [433]  8.63  9.90  7.59  7.39  7.78  7.47  6.97  8.82  9.13  7.86  7.13  9.45
## [445]  8.78  7.23  9.73  7.36  7.36  8.47  9.37  6.99  8.20  8.36  8.22  9.91
## [457]  9.67  8.60 10.07 10.15  7.75  9.21  9.66  8.47  9.37  9.44  9.99 10.38
## [469]  7.51  8.91  7.45  9.57  8.99  8.58  6.90  7.55  7.93  9.71  9.57  8.55
## [481]  6.62  7.89  7.51  7.36  8.66  8.51  6.65  9.67  7.80  8.21  7.90  8.94
## [493]  9.82  8.69  8.57  8.89  5.98  7.92  7.60  8.22  5.70  8.75  6.93  7.97
## [505]  8.06 10.13  7.31  8.35  5.57  9.85  9.16  9.03 10.07  9.76  9.35 10.95
## [517]  8.87  6.68  9.69  8.05 10.30  6.07  8.51  7.71  8.56  8.26  8.62 10.92
## [529] 10.51  9.83  9.84  9.74  8.21  8.72  8.03  9.00  6.19  8.22  7.93 10.18
## [541]  8.98  9.13  6.91  8.79  8.23 10.24  8.83  7.62  8.96 10.41  8.97  9.61
## [553]  8.29  8.30  8.26  7.44  9.52  8.20  8.68  8.65 10.52  8.41  9.18  8.42
## [565]  8.86  7.92 10.97  8.85  9.31 10.28  7.56  7.88  7.99  8.23  8.52  9.14
## [577]  6.20  7.64  8.95  7.48  7.06  7.33  8.98  8.24  8.53  8.40  7.48  8.46
## [589]  9.29  8.57  8.70  8.50  8.37  6.87  7.50  7.39  8.19  7.56  8.37  7.39
## [601]  6.73  8.66  8.25  8.47  8.01  6.83  9.06  8.79  7.44  6.43  5.93  8.85
## [613]  9.86  8.55  7.66  7.82  9.08 10.10  8.21  8.85  7.79  7.58  7.85  7.18
## [625]  7.54  9.72  7.12  9.77  8.84  5.67  8.15  9.61  8.19  7.27  8.51  8.36
## [637] 10.00  8.74  6.18 10.26 10.16  8.31  8.58  7.04  8.81  5.99  8.22  9.86
## [649]  8.00  9.40  9.10  8.11  8.89  9.43  7.59  8.72  9.86  9.23  9.50 10.73
## [661]  7.59  7.41  9.26  7.78  7.76  8.94  8.95  6.41  6.11  7.76  7.38  6.21
## [673]  7.05  7.44  8.50  7.84 11.01  7.88  9.10  8.65  8.41  7.81  7.43  8.76
## [685]  7.58  9.55  6.82 10.24  6.24  7.31 10.52  9.27  7.13  9.14  8.48  8.57
## [697]  7.21  9.05  7.72  8.03  6.47  5.57  6.32  7.78  8.58 10.37  9.23  9.20
## [709]  6.93  9.32  7.11  9.79  8.21  8.42  7.05  9.26  8.77  9.25  9.30 10.63
## [721]  9.90  9.89  9.33  7.78  7.02 11.26  8.89  9.60  7.07  6.01  9.11  8.24
## [733]  8.97  8.59  7.17  7.94  7.27  9.59  7.94  8.52  7.59  9.17  8.08  9.80
## [745]  8.92  9.91  9.42  8.84 10.15  8.37  9.33  9.35  7.40  8.35  9.53  9.59
## [757] 10.05  8.57  8.48  8.43  8.45  8.84 11.18  8.64  8.42  6.34  7.93  8.36
## [769]  8.32  7.77  6.84  8.78  7.19  8.50  8.82  9.04  7.93  7.66 10.07  9.03
## [781]  8.13  7.51  9.08  7.10  7.88  9.40  9.06  8.38 10.65  7.77  8.50  8.61
## [793] 10.05  8.71  9.37  6.97  8.56  9.34  9.47  8.11  8.91  7.83  8.95  7.20
## [805]  9.37  5.84  9.81  9.27  9.50  9.32  8.92  8.38  7.74  8.60  9.49  8.35
## [817]  7.11  9.87  8.98  7.75  8.24  6.74  6.83  7.70  6.70  8.67  9.94  8.73
## [829]  9.63  6.66  8.29  8.47  8.16  8.97  7.51  8.97  8.55  5.84  7.85  8.68
## [841]  8.05  8.27  7.68  9.40  7.77  6.89  7.55  8.27  8.16  8.07  7.91  7.71
## [853] 10.16  8.41  8.88  9.64  7.93  7.78  8.90  8.55  9.15 10.86  9.08  7.44
## [865] 10.35  6.68  8.85  8.90  8.24  6.74 10.75  8.44  7.69  8.88  7.70  8.60
## [877]  8.44  9.50  9.03  7.15  7.95  8.23  9.81  8.48  9.33  8.97  8.08  7.47
## [889]  8.34  7.75  8.34  7.56  6.93 10.03  8.69  9.04  8.32  7.85  7.21  8.98
## [901]  7.09  8.85  9.21  8.61  7.91  7.47  8.65  8.53  9.92  8.09  7.06  8.45
## [913]  8.73  7.45  9.02  7.51  7.32  8.17  9.45  9.72  9.34  8.75  9.32  7.91
## [925]  7.49  6.53  6.18  8.69
boxplot(brightness.without)

##2.3. UScereal relationship between ...
# a) i manufacturer and shelf
data(UScereal)
barplot(table(UScereal$mfr, UScereal$shelf), beside = T,  main = "Relationship manufacturer and shelf", xlab = "shelf", ylab = "# manufacturer")

# ii. fat and vitamins
barplot(table(UScereal$fat, UScereal$vitamins), beside = T, main = "Relationsship fat and vitamins", 
        xlab = "vitamins", ylab = "fat")

# iii. fat and shelf
barplot(table(UScereal$fat, UScereal$shelf), beside = T, main = "Relationship fat and shelf")

cor(UScereal$fat, UScereal$shelf)
## [1] 0.3256975
#baja correlación.

# iv. Carbohydrates and sugars
plot(UScereal$carbo, UScereal$sugars)

cor(UScereal$carbo, UScereal$sugars)
## [1] -0.04082599
#  -0.0408 --> baja correlación negativa

# v. fiber and manufacturer (X = manufaturer , y = fiber)
plot(UScereal$mfr, UScereal$fibre)

# vi. sodium and sugars
cor(UScereal$sodium, UScereal$sugars) # 0.211, correlación baja positiva.
## [1] 0.2112437
plot(UScereal$sodium, UScereal$sugars)

## 2.4 mammals ---> relationship between body weight and brain weight of mammals.
# a) Linear correlation
data(mammals)
cor(mammals$body, mammals$brain) # 0.934, fuerte correlación positiva entre las variables.
## [1] 0.9341638
pairs(mammals$body ~ mammals$brain) # en este emparejamiento, se aprecia la correlación lineal existente #entre las variables.

# b) plot the data.
plot(mammals)

# c) Transform the data with log function.
pairs(log(mammals$body)~log(mammals$brain))

cor(log(mammals$body), log(mammals$brain)) # 0.959, mejora la realción lineal entre las variables
## [1] 0.9595748
#y así se puede apreciar en el plot.


## 2.5. emissions ---> CO2 and gross domestic products in 26 countries.
# a) Relationship  GDP, perCapita and CO2 of each country.
data(emissions)
cor(emissions) # correlación altamente positiva de CO2 con GDP, media entre GDP y perCapita
##                 GDP perCapita       CO2
## GDP       1.0000000 0.4325303 0.9501753
## perCapita 0.4325303 1.0000000 0.2757962
## CO2       0.9501753 0.2757962 1.0000000
# baja correlación positiva entre CO2 y perCapita y se puede apreciar en el gráfico.
pairs(emissions)

# b) Modelo de regresión lineal para predecir emisión de CO2 desde las variables.
reg_lineal= lm(emissions$CO2 ~ emissions$GDP + emissions$perCapita, data = emissions)
summary(reg_lineal) 
## 
## Call:
## lm(formula = emissions$CO2 ~ emissions$GDP + emissions$perCapita, 
##     data = emissions)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1037.3  -167.4    10.8   153.2  1052.0 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          5.100e+02  2.044e+02   2.495   0.0202 *  
## emissions$GDP        8.406e-04  5.198e-05  16.172 4.68e-14 ***
## emissions$perCapita -3.039e-02  1.155e-02  -2.631   0.0149 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 382.8 on 23 degrees of freedom
## Multiple R-squared:  0.9253, Adjusted R-squared:  0.9188 
## F-statistic: 142.5 on 2 and 23 DF,  p-value: 1.102e-13
CO2_predict = predict(reg_lineal, emissions)
plot(emissions$GDP + emissions$perCapita, CO2_predict)

CO2_predict
##  UnitedStates         Japan       Germany        France UnitedKingdom 
##   6403.720110   2357.274571   1328.457202    939.412260    915.510264 
##         Italy        Russia        Canada         Spain     Australia 
##    888.117914    948.030553    418.174003    551.546727    203.695487 
##   Netherlands        Poland       Belgium        Sweden       Austria 
##    137.905405    524.997147      3.295727     57.168681      6.260516 
##   Switzerland      Portugal        Greece       Ukraine       Denmark 
##    -65.251059    177.533136    235.468677    538.782254    -82.034073 
##        Norway       Romania CzechRepublic       Finland       Hungary 
##   -213.820805    449.888660    273.235200     -5.729292    353.120804 
##       Ireland 
##     59.239930
cor(emissions$CO2, CO2_predict) # 0.962 --> alta correlación positiva.
## [1] 0.9619321
# es un modelo ajustado con una buena confianza estadística, donde 
#la variable GDP es la que mejor explica la predicción de emisión de CO2


# c) identificar outliers y se corre el modelo sin los outliers
boxplot(emissions)

boxplot.stats(emissions$CO2)$out 
## [1] 6750 1320 1740 2000
outliers_emissions = which(emissions$CO2 %in% c(boxplot.stats(emissions$CO2)$out))
outliers_emissions
## [1] 1 2 3 7
CO2without.outliers = emissions$CO2[-c(outliers_emissions)]
CO2without.outliers
##  [1] 550 675 540 700 370 480 240 400 145  75  80  54  75 125 420  75  56 160 150
## [20]  76  85  63
GDPwithout.outliers = emissions$GDP[-c(outliers_emissions)]
GDPwithout.outliers
##  [1] 1320000 1242000 1240000  658000  642400  394000  343900  280700  236300
## [10]  176200  174100  172400  149500  137400  124900  122500  120500  114200
## [19]  111900  102100   73200   59900
perCapitawithout.outliers = emissions$perCapita[-c(outliers_emissions)]
perCapitawithout.outliers 
##  [1] 22381 21010 21856 21221 16401 20976 21755  7270 23208 19773 21390 23696
## [13] 15074 12833  2507 22868 27149  5136 10885 19793  7186 16488
reg_lineal2<- lm(CO2without.outliers ~ GDPwithout.outliers + perCapitawithout.outliers, data = emissions)
summary(reg_lineal2)
## 
## Call:
## lm(formula = CO2without.outliers ~ GDPwithout.outliers + perCapitawithout.outliers, 
##     data = emissions)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -130.88  -63.84  -32.27   16.79  334.38 
## 
## Coefficients:
##                             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                2.233e+02  7.202e+01   3.101  0.00588 ** 
## GDPwithout.outliers        4.912e-04  6.989e-05   7.028 1.09e-06 ***
## perCapitawithout.outliers -8.525e-03  4.114e-03  -2.072  0.05209 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 121.4 on 19 degrees of freedom
## Multiple R-squared:  0.7225, Adjusted R-squared:  0.6933 
## F-statistic: 24.73 on 2 and 19 DF,  p-value: 5.142e-06
plot(GDPwithout.outliers + perCapitawithout.outliers, CO2without.outliers )

CO2_predict_without_outliers = predict(reg_lineal2, emissions)
## Warning: 'newdata' had 26 rows but variables found have 22 rows
plot(GDPwithout.outliers + perCapitawithout.outliers, CO2_predict_without_outliers )

cor(CO2without.outliers, CO2_predict_without_outliers) # 0.85
## [1] 0.8499957
boxplot(emissions$CO2)

boxplot(CO2without.outliers)

## 2.6. Anorexia ---> cambio de peso en mujeres.

#a) cual tratamiento es más efectivo?
data(anorexia)

posicion_Wt = which(anorexia$Postwt>anorexia$Prewt)
exitosos = anorexia[c(posicion_Wt),]
mejor_tto = which.max(table(exitosos$Treat))
mejor_tto = c(paste(names(mejor_tto),": ",max(table(exitosos$Treat))," casos exitosos"))
table(exitosos$Treat)
## 
##  CBT Cont   FT 
##   18   11   13
mejor_tto  # --> CBT con 18 casos exitosos-
## [1] "CBT :  18  casos exitosos"
# b) Cuántos pacientes ganaron y cuántos perdieron peso?
posicion_perdida_peso <- which(anorexia$Postwt<anorexia$Prewt)
casos_fracaso = anorexia[c(posicion_perdida_peso),]
ganaron_peso = length(posicion_Wt)
ganaron_peso    # --> 42
## [1] 42
perdieron_peso = nrow(casos_fracaso)
perdieron_peso   # -_> 29
## [1] 29
## 2.7. Generar 2 vectores de 50 valores desde una distribución normal con rnorm (50)
x = rnorm(50, mean = 0, sd = 1)
y = rnorm(50, mean = 0, sd = 1)

# a) Test Shapiro-Wilk (normalidad para cada vector)
vector1 = c(x)
shapiro.test(vector1)  # pvalor > alfa --> no se rechaza Ho, lo que indica que es de distribución normal.
## 
##  Shapiro-Wilk normality test
## 
## data:  vector1
## W = 0.98636, p-value = 0.828
vector2= c(y)
shapiro.test(vector2) # pvalor > alfa --> No se rechaza Ho, lo que indica que la distribución  es normal.
## 
##  Shapiro-Wilk normality test
## 
## data:  vector2
## W = 0.95103, p-value = 0.03761
# b) t-students de ambos vectores
TEST = t.test(vector1, vector2)
TEST   # En este test t de student, tenemos un valor de p > 0.05 (alfa) lo que nos indica que ambas variables no difieren en su media ---> no hay diferencia significativa entre ambos vectores.
## 
##  Welch Two Sample t-test
## 
## data:  vector1 and vector2
## t = -0.082074, df = 97.575, p-value = 0.9348
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.3964094  0.3649236
## sample estimates:
##   mean of x   mean of y 
## -0.09970833 -0.08396544
boxplot(vector1,vector2,names=c("X1","X2"))
medias <- c(mean(vector1),mean(vector2))
points(medias,pch=18,col="red") # se demuestra que no hay diferencia significativa en sus medias.

## 2.8. 50 valores con rnorm y 50 valores con rbinom

vectorr = rnorm(50, mean = 0, sd = 1)
vectorb = rbinom(50, size = 30, prob = 0.3)

# a) Shapiro para cada vector.

shapiro.test(vectorr) # pvalor > alfa, NO se rechaza Ho, hay normalidad.
## 
##  Shapiro-Wilk normality test
## 
## data:  vectorr
## W = 0.9412, p-value = 0.01503
shapiro.test(vectorb) # pvalor > alfa, NO se rechaza Ho, hay normalidad.
## 
##  Shapiro-Wilk normality test
## 
## data:  vectorb
## W = 0.97081, p-value = 0.2496
# b) t de student entre los dos vectores.

TEST2 = t.test(vectorr, vectorb)
TEST2  # p valor < alfa, lo que indica que hay diferencias significativas entre ambos vectores
## 
##  Welch Two Sample t-test
## 
## data:  vectorr and vectorb
## t = -19.209, df = 59.356, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -10.045922  -8.150601
## sample estimates:
## mean of x mean of y 
## 0.1217386 9.2200000
## 2.9. 100 valores con rnor
vector12 = rnorm(100, mean = 0, sd = 1)
hist(vector12)  # al repetir el ejercicio de creación del vector, cambia la distribución en el histograma de manera aleatoria

summary(vector12)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -2.3692 -0.8401 -0.2374 -0.1390  0.5221  2.8367
## 2.10. Función pwr.t.test. y dos ejemplos prácticos.
# la función pwr.t.test, nos proporciona el poder de la prueba t. 
#ejemplo 1:
library(pwr)
pwr.t.test(n=110, d=0.65, sig.level = 0.05, type = "two.sample", alternative = "two.sided")
## 
##      Two-sample t test power calculation 
## 
##               n = 110
##               d = 0.65
##       sig.level = 0.05
##           power = 0.9977389
##     alternative = two.sided
## 
## NOTE: n is number in *each* group
#ejemplo 2:
pwr.t.test(n=35, d=0.8, sig.level = 0.01, type = "two.sample", alternative = "two.sided")
## 
##      Two-sample t test power calculation 
## 
##               n = 35
##               d = 0.8
##       sig.level = 0.01
##           power = 0.7545473
##     alternative = two.sided
## 
## NOTE: n is number in *each* group
# a medida que el nivel de significancia es menor, el poder de la prueba t disminuye