y1 <- function(x) {x^2/2}
y2 <- function(x) {2*x}
curve(y1,from = 0,to = 4, ylim = c(0,12),type = 'l')
curve(y2,from = 0,to =4, add = T, col ='red',type = 'l')
x <- seq(0,4, l=100)
polygon(x,y1(x),x,y2(x), col = 'darkcyan',density = 30)
text(2,3,'A')
text(1,4,'f(x)')
text(2,3,'A')
x0 <- 2.5
segments(x0,y1(x0),x0,y2(x0), col = 'red')
x0 <- 2.6
segments(x0,y1(x0),x0,y2(x0), col = 'red')
text(2.55,y2(2.55),'dx', pos=3)
\[dA = (y_2-y_1)*dx\] \[A = \int dA = \int (y_2-y_1)\ dx = \int (2x)-(\frac{x^2}{2})\ dx\] \[A = \int_{0}^{4}((2x)-(\frac{x^2}{2}))\ dx =
(x^2-\frac{x^3}{6})|_{0}^{4}\]
y1 <- function(x) {x^2/2}
y2 <- function(x) {2*x}
curve(y1,from = 0,to = 4, ylim = c(0,10),col = 'cyan',type = 'l',lwd=2)
curve(y2,from = 0,to =4, add = T, col ='cyan3',type = 'l',lwd=2)
abline(h=c(0,8),v=c(0,4))
n <- 10000
xn <- runif(n,0,4)
yn <- runif(n,0,8)
points(xn,yn,pch = 16, cex = 0.5, col = gray(0.5))
men_y2 <-sum(yn<=y2(seq(0,4,l=n)))
men_y1 <-sum(yn<=y1(seq(0,4,l=n)))
men_y1;men_y2
## [1] 3327
## [1] 4960
# Puntos dentro de A
puntos_A <- men_y2 - men_y1;puntos_A
## [1] 1633
(puntos_A*32)/n
## [1] 5.2256
library(agricolae)
dates<-c(14,21,28) # days
# example 1: evaluation - vector
evaluation<-c(40,80,90)
audps(evaluation,dates)
## evaluation
## 1470
audps(evaluation,dates,"relative")
## evaluation
## 0.7
mi_audps <- function(t,y){
audps(y,t)
}
tiempos <- seq(7,70,7)
daño <- sort(runif(n=length(tiempos),
min=5,20))
mi_audps(tiempos,daño)
## evaluation
## 838.0983
mi_trat_audps <- function(yt){
salida = c()
t <- unlist(yt[,1])
for(i in seq(2,ncol(yt))){
salida[i] <- mi_audps(t=t,y=unlist(yt[,i]))
}
salida <- salida[-1]
return(salida)
}
library(readxl)
df_da <- read_excel("D:/Kevin/Trabajos/Computacion estadistica/datos_audps.xlsx")
df_da
## # A tibble: 10 x 4
## Tiempo D_t1 D_t2 D_t3
## <dbl> <dbl> <dbl> <dbl>
## 1 7 20.1 6.25 7.85
## 2 14 26.0 16.3 30.5
## 3 21 27.0 17.8 36.5
## 4 28 30.4 25.6 44.3
## 5 35 42.8 33.0 47.8
## 6 42 43.1 61.2 50.3
## 7 49 55.5 65.9 67.7
## 8 56 60.2 74.0 73.7
## 9 63 66.4 74.9 77.8
## 10 70 66.8 78.6 79.2
audps_trat <- mi_trat_audps(df_da)
dfg <- data.frame(t = rep(df_da$Tiempo, 3),
y = c(df_da$D_t1,df_da$D_t2,df_da$D_t3),
trat = rep(1:3, each=nrow(df_da)));dfg
## t y trat
## 1 7 20.106662 1
## 2 14 25.982238 1
## 3 21 26.977905 1
## 4 28 30.397504 1
## 5 35 42.842189 1
## 6 42 43.126011 1
## 7 49 55.543229 1
## 8 56 60.240028 1
## 9 63 66.381115 1
## 10 70 66.790826 1
## 11 7 6.252022 2
## 12 14 16.329997 2
## 13 21 17.769707 2
## 14 28 25.611438 2
## 15 35 32.961058 2
## 16 42 61.224250 2
## 17 49 65.927915 2
## 18 56 74.026002 2
## 19 63 74.891202 2
## 20 70 78.638112 2
## 21 7 7.847377 3
## 22 14 30.457015 3
## 23 21 36.451613 3
## 24 28 44.318522 3
## 25 35 47.804498 3
## 26 42 50.306253 3
## 27 49 67.715537 3
## 28 56 73.680380 3
## 29 63 77.832423 3
## 30 70 79.214911 3
df_texto <- data.frame(label = round(audps_trat,2),
trat = 1:3)
df_da$Tiempo
## [1] 7 14 21 28 35 42 49 56 63 70
df_da[,1]
## # A tibble: 10 x 1
## Tiempo
## <dbl>
## 1 7
## 2 14
## 3 21
## 4 28
## 5 35
## 6 42
## 7 49
## 8 56
## 9 63
## 10 70
unlist(df_da[,1])
## Tiempo1 Tiempo2 Tiempo3 Tiempo4 Tiempo5 Tiempo6 Tiempo7 Tiempo8
## 7 14 21 28 35 42 49 56
## Tiempo9 Tiempo10
## 63 70
class(df_da$Tiempo)
## [1] "numeric"
class(df_da[,1])
## [1] "tbl_df" "tbl" "data.frame"
class(unlist(df_da[,1]))
## [1] "numeric"
library(ggplot2)
ggplot(data = dfg, aes(x = t, y = y))+
geom_line()+
geom_text(data = df_texto,
mapping = aes(x = 20, y = 60, label = label))+
facet_wrap(~trat)
library(lattice)
xyplot(y~t|trat, data = dfg, t='l')
library(ggpubr)
dfg$trat <- as.factor(dfg$trat)
dfg$t <- rownames(dfg)
ggviolin(dfg, x = "trat", y = "y", fill = "trat",
palette = c("cyan","darkgoldenrod1","firebrick1"),
add = "boxplot",
add.params = list(fill = "white"),
ylab = 'Daño',
xlab = 'Tratamiento',
width = 0.8,
ggtheme = theme_dark())
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
fig <- plot_ly(dfg, x = df_da$Tiempo, y = df_da$D_t1, type = 'bar', name = 'Trat1',
marker = list(color = 'chocolate3'))
fig <- fig %>% add_trace(y = df_da$D_t2, name = 'Trat2', marker = list(color = 'cyan3'))
fig <- fig %>% add_trace(y = df_da$D_t3, name = 'Trat3', marker = list(color = 'firebrick2'))
fig <- fig %>% layout(title = 'Daño en plantas según tratamiento',
xaxis = list(
title = "Tiempo en Días",
tickfont = list(
size = 14,
color = 'chocolate3')),
yaxis = list(
title = 'Daño',
titlefont = list(
size = 16,
color = 'cyan3'),
tickfont = list(
size = 14,
color = 'firebrick2')),
legend = list(x = 0, y = 1, bgcolor = 'white', bordercolor = 'black'),
barmode = 'group', bargap = 0.15, bargroupgap = 0.1)
fig
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## Warning: 'layout' objects don't have these attributes: 'bargroupgap'
## Valid attributes include:
## 'font', 'title', 'uniformtext', 'autosize', 'width', 'height', 'margin', 'paper_bgcolor', 'plot_bgcolor', 'separators', 'hidesources', 'showlegend', 'colorway', 'datarevision', 'uirevision', 'editrevision', 'selectionrevision', 'template', 'modebar', 'meta', 'transition', '_deprecated', 'clickmode', 'dragmode', 'hovermode', 'hoverdistance', 'spikedistance', 'hoverlabel', 'selectdirection', 'grid', 'calendar', 'xaxis', 'yaxis', 'ternary', 'scene', 'geo', 'mapbox', 'polar', 'radialaxis', 'angularaxis', 'direction', 'orientation', 'editType', 'legend', 'annotations', 'shapes', 'images', 'updatemenus', 'sliders', 'colorscale', 'coloraxis', 'metasrc', 'barmode', 'bargap', 'mapType'