r - Doing a linear fit for each group of a data frame, check heteroscedasticity -


i have data frame 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 linear adjust lm(mu~ord, data=df) each group of type , exp. have tried following not working..:

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

i need use fortify because need .fitted , .resid fields later on multiplot sorting plots type , exp using facet_grid contained in ggplot in order check if there's heteroscedasticity in each fitted model.. in orgnanized multiplot: enter image description here

any suggestions? :<

the documentation fortify() in ggplot2 package says method deprecated , broom package should used instead. based on info here, should this:

library(dplyr) library(broom)  intsl <- df %>%   group_by(exp, type) %>%   do(fit = lm(mu ~ ord, .)  intsl %>% augment(fit) 

this should give data frame variables used group regressions, regression variables, , output each observation such .fitted , .resid, can move on plot them ggplot directly.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -