library(profileR)
## Warning: package 'profileR' was built under R version 4.2.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.3
## Loading required package: RColorBrewer
## Loading required package: reshape
## Warning: package 'reshape' was built under R version 4.2.3
## Loading required package: lavaan
## Warning: package 'lavaan' was built under R version 4.2.3
## This is lavaan 0.6-15
## lavaan is FREE software! Please report any bugs.
datos=data.frame(id=rep(1:4,5), tiempo=rep(seq(0,28,7),each=4),A=sort(rnorm(20,3,0.3)),B=sort(runif(20,2.5,3.0)),C=sort(rexp(20,1/2)))
datos
## id tiempo A B C
## 1 1 0 2.458127 2.514098 0.09220569
## 2 2 0 2.638157 2.520984 0.18304044
## 3 3 0 2.689761 2.549784 0.27852277
## 4 4 0 2.712886 2.574221 0.28187099
## 5 1 7 2.775356 2.584190 0.28716532
## 6 2 7 2.858507 2.629636 0.37889417
## 7 3 7 2.887487 2.631875 0.58725202
## 8 4 7 2.888593 2.635489 0.72957035
## 9 1 14 2.934649 2.649496 0.91772359
## 10 2 14 2.965974 2.651231 1.03641747
## 11 3 14 2.980944 2.664708 1.09821940
## 12 4 14 2.982784 2.670404 1.10830047
## 13 1 21 3.049750 2.719034 1.15257886
## 14 2 21 3.099846 2.723974 1.15664985
## 15 3 21 3.187659 2.748542 1.30116461
## 16 4 21 3.220717 2.807558 1.76006714
## 17 1 28 3.298627 2.829149 1.93374881
## 18 2 28 3.315898 2.847856 1.93870727
## 19 3 28 3.494561 2.871413 2.05320766
## 20 4 28 3.498264 2.903878 3.11749437
#Aquí se observan las repeticiones de 4 tratamientos
tiemp=unique(datos$tiempo)
medA=tapply(datos$A,datos$tiempo,mean)
medB=tapply(datos$B,datos$tiempo,mean)
medC=tapply(datos$C,datos$tiempo,mean)
plot(tiemp,medA,type='o',ylim=c(0,8),col='black',ylab='Promedio')
lines(tiemp,medB,type='o',col='red')
lines(tiemp,medC,type='o',col='blue')
legend("topleft",c('A','B','C'),col=c('black','red','blue'),pch=16)

library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:reshape':
##
## rename
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(tidyr)
##
## Attaching package: 'tidyr'
## The following objects are masked from 'package:reshape':
##
## expand, smiths
datos %>%
#filter(id==1) %>%
pivot_longer(-c(id,tiempo))%>%
ggplot()+
aes(tiempo,value,color=name)+
geom_line(size=3)+
facet_wrap(~id,scales='free')
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

library(agricolae)
## Warning: package 'agricolae' was built under R version 4.2.3
df_audp=datos %>%
group_by(id) %>%
summarise(A1=audpc(A,tiempo),
B1=audpc(B,tiempo),
C1=audpc(C,tiempo),
A2=audps(A,tiempo),
B2=audps(B,tiempo),
C2=audps(C,tiempo))
df_audpc=df_audp %>%
select(id,A1,B1,C1) %>%
pivot_longer(-id,values_to = 'AUDPC')
df_audps=df_audp %>%
select(id,A1,B1,C1) %>%
pivot_longer(-id,values_to = 'AUDPS')
# ANOVA 1
mod1 = aov(AUDPC ~ name, df_audpc)
summary(mod1)
## Df Sum Sq Mean Sq F value Pr(>F)
## name 2 6996 3498 266.2 9.85e-09 ***
## Residuals 9 118 13
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
mod2 = aov(AUDPS ~ name, df_audps)
summary(mod2)
## Df Sum Sq Mean Sq F value Pr(>F)
## name 2 6996 3498 266.2 9.85e-09 ***
## Residuals 9 118 13
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#ANALISIS DE PERFILES
library(profileR)
datos_t = datos %>%
pivot_longer(-c(id, tiempo)) %>%
spread(tiempo, value)
mod3 = pbg(data = select(datos_t, -c(id, name)),
group = datos_t$name,
original.names = TRUE,
profile.plot = TRUE)

summary(mod3)
## Call:
## pbg(data = select(datos_t, -c(id, name)), group = datos_t$name,
## original.names = TRUE, profile.plot = TRUE)
##
## Hypothesis Tests:
## $`Ho: Profiles are parallel`
## Multivariate.Test Statistic Approx.F num.df den.df p.value
## 1 Wilks 2.920652e-03 26.255648 8 12 1.815463e-06
## 2 Pillai 1.699829e+00 9.910022 8 14 1.350831e-04
## 3 Hotelling-Lawley 1.007753e+02 62.984585 8 10 1.487997e-07
## 4 Roy 9.832829e+01 172.074505 4 7 4.571336e-07
##
## $`Ho: Profiles have equal levels`
## Df Sum Sq Mean Sq F value Pr(>F)
## group 2 8.566 4.283 213 2.64e-08 ***
## Residuals 9 0.181 0.020
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## $`Ho: Profiles are flat`
## F df1 df2 p-value
## 1 252.6928 4 6 8.183095e-07