── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Code
library(lme4)
Loading required package: Matrix
Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
Code
library(lmerTest)
Attaching package: 'lmerTest'
The following object is masked from 'package:lme4':
lmer
The following object is masked from 'package:stats':
step
Code
library(mmrm)library(GGally)
Registered S3 method overwritten by 'GGally':
method from
+.gg ggplot2
Code
library(car)
Loading required package: carData
mmrm() registered as car::Anova extension
Attaching package: 'car'
The following object is masked from 'package:purrr':
some
The following object is masked from 'package:dplyr':
recode
Code
library(emmeans)
mmrm() registered as emmeans extension
Welcome to emmeans.
Caution: You lose important information if you filter this package's results.
See '? untidy'
Attaching package: 'emmeans'
The following object is masked from 'package:GGally':
pigs
New names:
Rows: 256 Columns: 15
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," dbl
(14): PigID, KneeLeft, KneeRigth, HeelLeft, HeelRigth, Back, HockLeft, H... lgl
(1): ...15
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...15`
# A tibble: 64 × 4
Pen Sex PigID TRT
<dbl> <chr> <dbl> <dbl>
1 1 B 310 1
2 1 B 495 1
3 2 B 309 2
4 2 B 492 2
5 3 B 292 3
6 3 B 6 3
7 4 B 481 4
8 4 B 487 4
9 11 B 485 1
10 11 B 493 1
# ℹ 54 more rows
NOTE: Results may be misleading due to involvement in interactions
Code
em2%>%pairs()
contrast estimate SE df t.ratio p.value
TRT1 - TRT2 -2.93 2.04 24 -1.440 0.4877
TRT1 - TRT3 1.48 2.04 24 0.724 0.8864
TRT1 - TRT4 -1.81 2.04 24 -0.889 0.8107
TRT2 - TRT3 4.41 2.04 24 2.165 0.1620
TRT2 - TRT4 1.12 2.04 24 0.552 0.9452
TRT3 - TRT4 -3.29 2.04 24 -1.613 0.3905
Results are averaged over the levels of: Sex
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 4 estimates
How to do it with tidyverse
reformat
Code
data_long<-dts%>%ungroup()%>%select(-'...15')%>%pivot_longer(KneeLeft:RearLeg,names_to ="Pheno",values_to ="y") #move to long format#check: Always check!N_pivoted<-dts%>%ungroup()%>%select(KneeLeft:RearLeg)%>%ncol() #number of pivoted columnsN_obs<-nrow(dts) #number of rows in wide formatexpected_length<-N_pivoted*N_obs #number of rows in long format: pivoted*rows in wideexpected_cols<-ncol(dts)-1-N_pivoted+2#number of cols in long f: cols in wide -1 (15 fake column) - number pivoted +2 (value and name columns)dim(data_long)
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
Warning: Model failed to converge with 1 negative eigenvalue: -2.6e-04
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
boundary (singular) fit: see help('isSingular')
Code
length(lmef) #check splits: number of variables by number of periods (4) = 48
Warning: `as.tibble()` was deprecated in tibble 2.0.0.
ℹ Please use `as_tibble()` instead.
ℹ The signature and semantics have changed, see `?as_tibble`.
Code
dim(anv) #number of rows: 48*4 terms = 192
[1] 192 6
Code
emm<-lmef%>%map(emmeans,specs="TRT")
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
NOTE: Results may be misleading due to involvement in interactions
Code
emd<-emm%>%map(pairs)%>%map(data.frame)%>%map_dfr(bind_rows,.id="Pheno")emm<-emm%>%map(data.frame)%>%map_dfr(bind_rows,.id="Pheno")dim(emm) # #number of rows: 48*4 treatments = 192
[1] 192 7
Code
dim(emd) # #number of rows: 48*6 mean differences = 288
[1] 288 7
Represent results
A key step in highthroughput data analyses is to represent outputs in a meaningful way.
We start looking at the ANOVA tables
Code
anv<-mutate(anv,period=as.factor(str_split_i(Pheno,"[.]",2)),Pheno=as.factor(str_split_i(Pheno,"[.]",1)))emm<-mutate(emm,period=as.factor(str_split_i(Pheno,"[.]",2)),Pheno=as.factor(str_split_i(Pheno,"[.]",1)))emd<-mutate(emd,period=as.factor(str_split_i(Pheno,"[.]",2)),Pheno=as.factor(str_split_i(Pheno,"[.]",1)))filter(anv,term=="Sex:TRT")%>%summary() #no interaction Sex by trt
Pheno Chisq Df Pr..Chisq.
Back : 4 Min. :0.3874 Min. :3 Min. :0.0686
FrontLeg : 4 1st Qu.:1.0039 1st Qu.:3 1st Qu.:0.3749
HeelLeft : 4 Median :1.8867 Median :3 Median :0.5966
HeelRigth: 4 Mean :2.2919 Mean :3 Mean :0.5757
HockLeft : 4 3rd Qu.:3.1136 3rd Qu.:3 3rd Qu.:0.8003
HockRigth: 4 Max. :7.1058 Max. :3 Max. :0.9428
(Other) :24
term lpval period
Length:48 Min. :0.02557 1:12
Class :character 1st Qu.:0.09678 2:12
Mode :character Median :0.22469 3:12
Mean :0.30687 4:12
3rd Qu.:0.42669
Max. :1.16367