R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

set.seed(2020)
x<-sort.int(runif(120,3,5),partial = 30)
y<-sort.int(runif(120,10,20),partial = 30)
plot(x,y)

cor(x,y) #0.2922963
## [1] 0.88835

\[H_o:\rho =0\]

\[H_a:\rho \neq 0\]

cor.test(x,y,alternative = "t",method = "pearson", conf.level = 0.95)
## 
##  Pearson's product-moment correlation
## 
## data:  x and y
## t = 21.016, df = 118, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.8434029 0.9209495
## sample estimates:
##     cor 
## 0.88835

Investigar ¿como contrastar la siguiente hipotesis ? \[H_o:\rho = 0.4\]

\[H_a:\rho > 0.4\]

set.seed(1234)
biomasa<-rnorm(100,3,0.5)+runif(100,3,4)
hist(biomasa)

shapiro.test(biomasa)
## 
##  Shapiro-Wilk normality test
## 
## data:  biomasa
## W = 0.9692, p-value = 0.01921
library(nortest)
ad.test(biomasa)
## 
##  Anderson-Darling normality test
## 
## data:  biomasa
## A = 0.569, p-value = 0.1368
sf.test(biomasa)
## 
##  Shapiro-Francia normality test
## 
## data:  biomasa
## W = 0.97131, p-value = 0.02891
pearson.test(biomasa)
## 
##  Pearson chi-square normality test
## 
## data:  biomasa
## P = 9.98, p-value = 0.4422
cvm.test(biomasa)
## 
##  Cramer-von Mises normality test
## 
## data:  biomasa
## W = 0.066796, p-value = 0.305
n=5
for(i in 1:n){
  x=i^2
}
x
## [1] 25
n=5
for(i in 1:n){
  x[i]=i^2
}
x
## [1]  1  4  9 16 25
h=5
e=c()
for(i in 1:n){
  x[i]=i^2
  e[i]=log(x[i])
}
h;e
## [1] 5
## [1] 0.000000 1.386294 2.197225 2.772589 3.218876
n.caras=6; n.lanzamientos=1200
resultado1=c();resultado2=c();suma=c()
for(j in 1:n.lanzamientos){
  resultado1[j]=sample(1:n.caras,1)
  resultado2[j]=sample(1:n.caras,1)
  suma[j]=sample(1:n.caras,1)
  
}
tabla1=table(resultado1)
tabla2=table(resultado2)
table_s=(suma)
tabla1
## resultado1
##   1   2   3   4   5   6 
## 185 200 216 209 185 205
tabla2
## resultado2
##   1   2   3   4   5   6 
## 202 194 192 183 214 215
table_s
##    [1] 5 5 2 5 5 4 4 1 5 3 4 5 6 6 4 3 4 3 3 6 4 2 3 4 1 2 6 3 3 5 5 3 1 5 6 1 6
##   [38] 6 6 4 6 5 3 4 6 1 2 3 3 4 3 6 5 3 2 2 5 2 4 6 4 3 3 5 5 5 2 3 4 2 1 5 6 6
##   [75] 2 2 1 3 5 3 6 1 4 1 6 2 5 6 5 3 3 6 1 6 2 1 2 1 3 6 3 5 3 1 6 6 5 4 5 5 4
##  [112] 4 6 3 2 5 1 2 3 2 2 5 6 5 4 3 1 3 6 1 2 1 6 1 3 2 1 3 5 4 2 1 5 1 5 3 6 3
##  [149] 3 6 4 6 3 3 3 3 3 6 6 2 1 1 1 2 6 4 2 2 1 3 4 3 3 2 4 1 4 5 4 2 2 5 1 1 4
##  [186] 3 1 3 1 3 5 3 3 2 1 1 3 5 5 3 1 5 4 5 2 4 1 5 1 3 3 6 3 3 3 6 3 4 6 5 3 6
##  [223] 2 5 3 1 3 5 6 1 4 5 1 5 2 6 6 1 3 4 1 2 6 5 4 5 6 3 5 1 2 4 2 2 1 2 1 1 2
##  [260] 2 5 5 4 1 4 2 4 5 5 1 5 3 4 1 5 5 6 3 2 3 6 3 4 3 5 4 5 3 5 6 1 3 2 3 6 2
##  [297] 6 5 6 6 5 6 2 6 6 4 2 3 1 1 2 5 4 1 5 5 1 1 4 2 3 6 2 1 2 6 4 4 6 4 6 4 4
##  [334] 4 3 6 5 4 3 4 4 5 1 5 2 3 5 4 6 3 1 1 2 6 5 3 1 6 3 4 2 3 4 4 1 3 1 4 6 3
##  [371] 2 6 4 6 5 3 5 5 4 2 2 5 6 2 1 2 5 3 4 2 2 2 4 1 4 4 6 6 3 5 4 5 2 4 6 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3 2 6 5 5 5 4 2 2 5
##  [889] 1 1 6 6 2 3 2 1 5 1 5 2 3 6 2 1 6 5 1 6 4 4 2 6 4 2 5 3 1 3 3 1 2 2 1 4 6
##  [926] 3 3 6 1 2 5 2 2 1 5 2 2 6 1 4 2 1 1 5 3 5 2 4 1 4 3 5 3 6 6 5 6 4 4 4 5 4
##  [963] 6 3 6 3 2 2 2 5 6 1 2 5 5 6 4 5 5 4 3 2 3 6 3 2 5 5 5 2 3 5 4 6 1 1 5 1 3
## [1000] 2 1 6 4 5 1 4 6 1 5 6 4 1 4 5 6 1 3 4 2 6 2 5 5 4 4 1 5 1 6 2 3 6 2 2 3 6
## [1037] 3 5 3 6 5 4 1 6 2 6 5 5 4 2 1 4 5 4 4 3 2 2 5 3 4 5 2 3 3 2 3 2 3 6 4 3 2
## [1074] 1 6 2 4 5 3 5 3 1 5 6 3 4 2 2 3 1 5 6 1 5 3 3 5 1 4 2 3 4 5 5 5 3 3 5 4 3
## [1111] 1 4 3 3 2 5 4 6 2 1 4 1 3 3 6 3 2 5 6 2 1 6 2 4 5 1 4 5 6 3 3 1 3 5 3 4 2
## [1148] 6 1 1 2 4 4 4 5 2 1 5 2 4 6 3 3 2 6 6 5 4 1 5 6 1 5 6 5 3 5 2 1 5 6 6 3 3
## [1185] 5 3 4 3 2 6 5 3 6 1 1 1 2 3 4 5
set.seed(2020)
m<-100
x<-runif(m,0,1)
y<-runif(m,0,1)
d<-(x^2+y^2<1)
plot(x,y,col=d+1,pch=19)

table(d)
## d
## FALSE  TRUE 
##    25    75
prop.table(table(d))
## d
## FALSE  TRUE 
##  0.25  0.75

\[area~cuadrada\to 1 \\area~\frac{1}{4}~ circulo \to x\]

\[100~puntos \to 1 \\75~ puntos \to x \]

\[?rea~\frac{1}{4} circulo=\frac{\pi r^2}{4} = \frac{\pi}{4}\]

set.seed(2020)
m<-1000
x<-runif(m,0,1)
y<-runif(m,0,1)
d<-(x^2+y^2<1)
plot(x,y,col=d+1,pch=19)

table(d)
## d
## FALSE  TRUE 
##   194   806
prop.table(table(d))
## d
## FALSE  TRUE 
## 0.194 0.806
set.seed(2020)
m<-10000
x<-runif(m,0,1)
y<-runif(m,0,1)
d<-(x^2+y^2<1)
plot(x,y,col=d+1,pch=19)

table(d)
## d
## FALSE  TRUE 
##  2097  7903
prop.table(table(d))
## d
##  FALSE   TRUE 
## 0.2097 0.7903
set.seed(2020)
m<-100000
x<-runif(m,0,1)
y<-runif(m,0,1)
d<-(x^2+y^2<1)
plot(x,y,col=d+1,pch=19)

table(d)
## d
## FALSE  TRUE 
## 21387 78613
prop.table(table(d))
## d
##   FALSE    TRUE 
## 0.21387 0.78613
curve(2/x,to=0,from=1)
segments(x0 =0.1 ,y0 =0 ,x1 =0.1, y1 =2/0.1)
abline(h=0,v=0,col="blue")
text(0.05,25,"A")

\[dA=f(x)dex\]

\[A=\int f(x)dx\]

\[A=\int_0^{0.1}\frac{2}{x}dx\]

\[A=\lim_{b\to 0}\int_b^{0.1}\frac{2}{x}dx\]

\[A=\lim_{b\to 0}2\ln(x) |_b^{0.1}\]

\[A=2\lim_{b\to 0} (\ln (0.1) - \ln(b))\] \[A=2\lim_{b\to 0} \ln (0.1/b) \] \[A=2\lim_{b\to 0^+} \ln (0.1/b)\]

curve(2/x,to=0,from=1)
segments(x0 =0.1 ,y0 =0 ,x1 =0.1, y1 =2/0.1)
abline(h=0,v=0,col="blue")
text(0.05,25,"A")
abline(h=200,v=1,col="blue")
xx=runif(10000,0,1)
yy=runif(10000,0,200)
points(xx,yy,pch=16,cex=0.5, col=ifelse(yy<2/xx & xx<0.1,"red","blue"))

table(ifelse(yy<2/xx & xx<0.1,"red","blue"))
## 
## blue  red 
## 9662  338

Con la integral

f = function(x) 2/x
integrate(f,0.01,0.15)
## 5.4161 with absolute error < 6.5e-06
curve(f,to=0,from=1)
segments(x0 =0.1 ,y0 =0 ,x1 =0.1, y1 =2/0.1)
abline(h=0,v=0,col="blue")
text(0.05,25,"A")
abline(h=200,v=1,col="blue")

curve(f,0,n=200, lwd=3)
segments(x0 =0.1 ,y0 =0 ,x1 =0.1, y1 =2/0.1)
abline(h=0,v=0,col="blue")
text(0.05,25,"A")
abline(h=200,v=1,col="blue")
xx=runif(1000,0,1)
yy=runif(1000,0,200)
points(xx,yy,pch=16,cex=0.5, col=ifelse(yy<2/xx & xx<0.1,"red","blue"))

table(ifelse(yy<2/xx & xx<0.1,"red","blue"))
## 
## blue  red 
##  968   32
curve(f,0,n=200, lwd=3)
segments(x0 =0.1 ,y0 =0 ,x1 =0.1, y1 =2/0.1)
abline(h=0,v=0,col="blue")
text(0.05,25,"A")
abline(h=200,v=1,col="blue")
xx=runif(10000,0,1)
yy=runif(10000,0,200)
points(xx,yy,pch=16,cex=0.5, col=ifelse(yy<2/xx & xx<0.1,"red","blue"))

Ok

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.