*Se omiten las tildes y caracteres para evitar errores de edicion en todo el documento.

Edicion de resultados, para analisis de experimentos

set.seed(2016)
VAR1 <- rnorm(100,12,.5)
hist(VAR1, prob=T, col=32, main="Histograma", breaks=15)
lines(density(VAR1))

Diagrama de cajas

set.seed(6)
VAR2 <- rnorm(100,12,.5)
boxplot(VAR2)

boxplot(VAR2, horizontal=T)

ward<-read.table("ward.csv", header=T, sep=",")
boxplot(EGGS~ZONE, data=ward, ylab="Number of eggs percapsule", xlab="Zone")

furness<-read.table("furness.csv", header=T, sep=",")
boxplot(METRATE~SEX, data= furness, ylab="metabolicrate", xlab="Sex")

limpets <-read.table("limpets.csv", header=T, sep=",")
boxplot(O2~SEAWATER*SPECIES, limpets, cex.axis=.7)

Cargue la base de datos “christ.csv”

christ <- read.table("christ.csv", header=T, sep=",")
#Elabora una figura de la distribucion de los datos de la variable "x" y "y"
plot(CWD.DENS ~ RIP.DENS, data=christ)
#dibuja la pendiente de los datos
abline(lm(CWD.DENS ~ RIP.DENS,data=christ))
#permite dibujar y calcular la media de los datos
abline(h=mean(christ$CWD.DENS),lty=2)

#Permite hacer cortes de datos segun la cantidad requerida
area <- cut(christ$AREA,2,lab=c("small", "large"))
area
##  [1] small small small small small large large small large small small
## [12] small small large small small
## Levels: small large
#Creamos un vector con un subset de datos de la regresion con los valores que categorizamos
lm.small <- lm(CWD.DENS ~ RIP.DENS, data=christ, subset=area=="small")
lm.large <- lm(CWD.DENS ~ RIP.DENS, data=christ,subset=area=="large")
plot(CWD.DENS ~ RIP.DENS, data=christ)
#agregamos las lineas de la pendiente para "lm.small"
lines(christ$RIP.DENS[area=="small"], predict(lm.small), lty=1)
#agregamos las lineas de la pendiente para "lm.large"
lines(christ$RIP.DENS[area=="large"], predict(lm.large), lty=2)
#agregamos una legenda 
legend("bottomright",title="Area",legend=c("small","large"), lty=c(1,2))

library(car)
#genera scatterplot
scatterplot(CWD.DENS ~  RIP.DENS, data=christ)

library(car)
#figura exploratoria
scatterplot.matrix(~CWD.DENS + RIP.DENS + CABIN + AREA,data=christ, diag="boxplot")
## Warning: 'scatterplot.matrix' is deprecated.
## Use 'scatterplotMatrix' instead.
## See help("Deprecated") and help("car-deprecated").

library(corrplot)
## Warning: package 'corrplot' was built under R version 3.2.3
christ <- read.table("christ.csv", header=T, sep=",")
#Para trabajar esto los datos deben estar ordenadas en Data frame
attach(christ)
a<-data.frame(AREA, RIP.DENS,RIP.BASA, CWD.DENS,CABIN)
Corr <- cor(a)
Corr
##                AREA   RIP.DENS   RIP.BASA   CWD.DENS      CABIN
## AREA      1.0000000 -0.0305865  0.4518667 -0.2748671 -0.0259550
## RIP.DENS -0.0305865  1.0000000  0.3950002  0.8740920 -0.6126756
## RIP.BASA  0.4518667  0.3950002  1.0000000  0.1772555 -0.2625449
## CWD.DENS -0.2748671  0.8740920  0.1772555  1.0000000 -0.7124502
## CABIN    -0.0259550 -0.6126756 -0.2625449 -0.7124502  1.0000000
corrplot(Corr, method = "ellipse")

Supuestos basicos para el diseño experimental.

#Utilice la base de datos de R "ChickWeight"
head(ChickWeight)
## Grouped Data: weight ~ Time | Chick
##   weight Time Chick Diet
## 1     42    0     1    1
## 2     51    2     1    1
## 3     59    4     1    1
## 4     64    6     1    1
## 5     76    8     1    1
## 6     93   10     1    1
#Contraste los supuestos parametricos, para los tratamientos de Dieta y weight
#Forma grafica
plot(aov(weight~Diet, data=ChickWeight))

#Calculo de valores
reg<-lm(weight~Diet, data=ChickWeight)
residuos<-residuals(reg) #Estima los residuos
#Normalidad
shapiro.test(residuos) 
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.94065, p-value = 2.014e-14
## Bartlett Test de Homogeneidad de Varianzas
bartlett.test(weight~Diet, data=ChickWeight)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  weight by Diet
## Bartlett's K-squared = 29.489, df = 3, p-value = 1.768e-06
library (outliers)
cochran.test(weight~Diet, data=ChickWeight)
## 
##  Cochran test for outlying variance
## 
## data:  weight ~ Diet
## C = 0.3642, df = 144.5, k = 4.0, p-value = 6.466e-05
## alternative hypothesis: Group 3 has outlying variance
## sample estimates:
##        1        2        3        4 
## 3209.965 5127.633 7489.476 4737.392
head(Orange)
## Grouped Data: circumference ~ age | Tree
##   Tree  age circumference
## 1    1  118            30
## 2    1  484            58
## 3    1  664            87
## 4    1 1004           115
## 5    1 1231           120
## 6    1 1372           142
plot(aov(circumference~Tree, data=Orange))

exp <- read.table("supuestosaov.csv", header=T, sep=";")
exp
##    Proteina Metodo  var1
## 1       Ubi    AVG 0.467
## 2       Ubi    GOR 0.645
## 3       Ubi    PHD 0.868
## 4       Deo    AVG 0.472
## 5       Deo    GOR 0.844
## 6       Deo    PHD 0.879
## 7       Rab    AVG 0.405
## 8       Rab    GOR 0.604
## 9       Rab    PHD 0.787
## 10      Alb    AVG 0.449
## 11      Alb    GOR 0.772
## 12      Alb    PHD 0.780
attach(exp)
is.factor(Proteina) 
## [1] TRUE
par(mfrow=c(2,2))
plot(aov(var1~Metodo,data=exp))