Perform a linear fit for each group of data frame to check for heterosexuality

I have a data frame like this:

ORD   exp type         mu
1   Combi pH=7 exp_F   mu 0.15637365
2   Combi pH=7 exp_F   mu 0.12817901
3   Combi pH=7 exp_F   mu 0.13392221
4   Combi pH=7 exp_F   mu 0.09683254
5   Combi pH=7 exp_F   mu 0.11249738
6   Combi pH=7 exp_F   mu 0.10878719
7   Combi pH=7 exp_F   mu 0.11019295
8   Combi pH=7 exp_F   mu 0.12100511
9   Combi pH=7 exp_F   mu 0.09803942
10  Combi pH=7 exp_F   mu 0.13842086
11  Combi pH=7 exp_F   mu 0.12778964
12     ORD0793 exp_F   mu 0.13910441
13     ORD0793 exp_F   mu 0.12603702
14     ORD0793 exp_F   mu 0.12670842
15     ORD0795 exp_F   mu 0.12982122
16     ORD0795 exp_F   mu 0.13648100
17     ORD0795 exp_F   mu 0.13593685
18     ORD0799 exp_F   mu 0.13906691
continues...

I would like to do a linear type setup lm(mu~ORD, data=df), but for each type group and exp. I tried the following but did not work .:

intsl <- df %>% group_by(exp,type) %>% 
  fortify(lm(mu~ORD)) %>% 
  select(exp,type, .fitted, .resid) 

I need to use fortify because I need the .fitted and .resid fields to later sort the sorting graphs by type and exp using the ones facet_gridcontained in ggplot to check if heterosedicity exists in each model. but in orgnanized multipot: enter image description here

Any suggestions ?: & L;

+4
source share
1 answer

fortify() ggplot2 , broom. , - :

library(dplyr)
library(broom)

intsl <- df %>%
  group_by(exp, type) %>%
  do(fit = lm(mu ~ ORD, .)

intsl %>% augment(fit)

, , , .fitted .resid, ggplot.

+1

Source: https://habr.com/ru/post/1683743/


All Articles