## R-USERS-L@LISTS.UFL.EDU

#### View:

 Message: [ First | Previous | Next | Last ] By Topic: [ First | Previous | Next | Last ] By Author: [ First | Previous | Next | Last ] Font: Proportional Font

Subject:

Re: How to store result of coefficients from the model

From:

Date:

Wed, 21 Feb 2018 17:48:09 +0000

Content-Type:

text/plain

Parts/Attachments:

 text/plain (254 lines)
 ```Make sure to double check your results. data = bb_1 (should be data = .) seems like a flag for me. ________________________________________ From: UF R Users List <[log in to unmask]> on behalf of Pattamanont,Pornpamol <[log in to unmask]> Sent: Wednesday, February 21, 2018 12:33 PM To: [log in to unmask] Subject: Re: How to store result of coefficients from the model I got it, finally!!!!! thanks you guys so much ðŸ˜Š it works by this code: > mod_pregsea <- bb_1 %>% group_by(HERDCODE) %>% do(broom::tidy(lm(as.numeric(conc_dry) ~ pregsea, data = bb_1))) Dr. Valle's code is what I want, but it turned error. I'll keep learning it. Thank you for you attention! ________________________________ From: UF R Users List <[log in to unmask]> on behalf of Ben Bolker <[log in to unmask]> Sent: Wednesday, February 21, 2018 11:29:55 AM To: [log in to unmask] Subject: Re: How to store result of coefficients from the model I would avoid using .\$ in the model formula, i.e.: model_multi_1T = bb_1 %>%     group_by(HERDCODE) %>%     do(broom::tidy( lm(conc_dry ~ pregsea, data=.))) On Wed, Feb 21, 2018 at 9:44 AM, Shawn Taylor <[log in to unmask]> wrote: > Thanks! I was just about to suggest this. But I usually run into issues > with the variables inside the lm() function, if that gives any trouble try > > library(dplyr) > > model_multi_1T = bb_1 %>% > group_by(HERDCODE) %>% > do(broom::tidy( lm(.\$conc_dry ~ .\$pregsea, data=.))) > > > > > On Wed, Feb 21, 2018 at 9:29 AM, Li,Daijiang <[log in to unmask]> wrote: > >> Try this: >> >> library(dplyr) >> library(broom) >> bb_1 %>% >> group_by(HERDCODE) %>% >> do(broom::tidy(lm(conc_dry ~ pregsea, data = .))) >> >> >> ________________________________________ >> From: UF R Users List <[log in to unmask]> on behalf of >> Pattamanont,Pornpamol <[log in to unmask]> >> Sent: Wednesday, February 21, 2018 8:21 AM >> To: [log in to unmask] >> Subject: Re: How to store result of coefficients from the model >> >> coef(mode) doesn't work for me as well. It gives only 1 group at a time. >> [cid:bca9fab7-94fc-4abb-bfd8-23d485e0f793] >> >> Do I need to write a loop to extract results for 1,200 groups? I don't >> know how to write it anyway T_T. >> ________________________________ >> From: Pattamanont,Pornpamol >> Sent: Wednesday, February 21, 2018 8:18:20 AM >> To: [log in to unmask] >> Subject: Re: How to store result of coefficients from the model >> >> >> It works for the whole data, but I want the results by group. >> >> >> > broom::tidy(lm(as.numeric(bb_1\$conc_dry) ~ bb_1\$pregsea, data=bb_1)) >> term estimate std.error statistic p.value >> 1 (Intercept) 166.78889823 0.2942663 566.7957739 <(566)%20795-7739> >> 0.000000e+00 >> 2 bb_1\$pregsea2 -0.54991912 0.4077014 -1.3488283 1.774491e-01 >> 3 bb_1\$pregsea3 0.09162663 0.3971105 0.2307334 8.175308e-01 >> 4 bb_1\$pregsea4 -1.75059740 0.3978579 -4.4000571 1.103208e-05 >> >> This's my code: >> model_multi_1T <- dlply(bb_1,c("HERDCODE"), function(bb_1) >> lm(bb_1\$conc_dry ~ bb_1\$pregsea, data=bb_1)) >> >> I want to store the coefficients for each group (111000200 is the number >> of the 1st group) >> [cid:6eb85a80-0160-49cb-90b6-12216571b0cc] >> >> >> >> ________________________________ >> From: UF R Users List <[log in to unmask]> on behalf of Shawn Taylor >> <[log in to unmask]> >> Sent: Wednesday, February 21, 2018 8:03:49 AM >> To: [log in to unmask] >> Subject: Re: How to store result of coefficients from the model >> >> tidy won't work on a list of model results, it needs to be run on the model >> output directly like: >> >> broom::tidy(lm(y~x, data=d)) >> >> Can you post or give a link to your analysis script and we can suggest >> where to implement it? >> >> >> >> On Wed, Feb 21, 2018 at 7:57 AM, Pattamanont,Pornpamol < >> [log in to unmask] >> > wrote: >> >> > It doesn't work. I've got this error. >> > >> > >> > [cid:53cc4333-2199-4ce2-9d8a-fad91ee9f438] >> > >> > >> > I've tried broom earlier; it doesn't work for any function in it. I think >> > the problem is because I run the model by group. I supposed to be able to >> > use "ldply" as it works for the previous model of mind that also run by >> > group. Only one difference that I can use ldply for this current model is >> > because the predictor is a category. >> > >> > >> > Any other suggestions? >> > >> > >> > >> > >> > >> > >> > >> > ________________________________ >> > From: UF R Users List <[log in to unmask]> on behalf of >> > Chaudhary,Vratika <[log in to unmask]> >> > Sent: Wednesday, February 21, 2018 6:35:29 AM >> > To: [log in to unmask] >> > Subject: Re: How to store result of coefficients from the model >> > >> > Pornpamol >> > >> > I am unsure if I understood your question right, but if storing model >> > results is your problem- you could use broom::tidy, which cleans and >> stores >> > gym results in data frame. https://urldefense.proofpoint.com/v2/url?u=https-3A__urldefense.proofpoint&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=KOLF1vxBdafTXhLO69TErJDpzpSd4q69Z4mESZUverg&s=g3FrOYAsMPrmKtNPtyf91yfYH2zsmKMOmitLM8wZE1w&e=. >> com/v2/url?u=https-3A__cran.r-2Dproject.org_&d=DwIBaQ&c=pZJP >> UDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggU >> L7kQsdfEWUTu6qCGEw8Xuo91A&m=tRJQgGL9yUTACFh99WH_vy1dT68htuYJ >> h-ugiZvUp_I&s=KBdGtazjdjQYkpp3v_beTgofUb0H-N4qJVuyre-v9b0&e= >> > web/packages/broom/vignettes/broom.html >> > >> > If you have small numbers of models you could do so for each of them and >> > then bind rows of the results in a table, else you could create a >> function >> > probably to do that >> > >> > Hope that helps >> > Vratika >> > >> > > On 21-Feb-2018, at 5:59 AM, Pattamanont,Pornpamol < >> [log in to unmask]> >> > wrote: >> > > >> > > Hello everyone, >> > > >> > > I'm struggling with storing results of coefficients from the model. I >> > was trying to use function "ldply" as ldply(model_multi_1T,coef) but >> there >> > was an error showing that "result do not have enough length". I have >> around >> > 1,200 lists in "model_multi_1T" . The attached picture is the >> coefficients >> > that I want to store in a table. >> > > >> > > >> > > any suggestions are appreciated, >> > > >> > > Pornpamol >> > > >> > > >> > > [cid:5762deff-8145-4095-aba7-b6c43ec935f0] >> > > >> > > >> > > >> > > This list strives to be beginner friendly. However, we still ask that >> > you >> > > PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=https-3A__urldefense.proofpoint&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=KOLF1vxBdafTXhLO69TErJDpzpSd4q69Z4mESZUverg&s=g3FrOYAsMPrmKtNPtyf91yfYH2zsmKMOmitLM8wZE1w&e=. >> com/v2/url?u=http-3A__www.R-2Dproject.org_&d=DwIBaQ&c=pZJPUD >> Q3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7 >> kQsdfEWUTu6qCGEw8Xuo91A&m=tRJQgGL9yUTACFh99WH_vy1dT68htuYJh- >> ugiZvUp_I&s=JxyBMGnGSSbvzgnGxb_rhGYCRWZG_3euARM8qQG7AjI&e= >> > posting-guide.html >> > > and provide commented, minimal, self-contained, reproducible code. >> > > >> > >> > This list strives to be beginner friendly. However, we still ask that >> you >> > PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=https-3A__urldefense.proofpoint&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=KOLF1vxBdafTXhLO69TErJDpzpSd4q69Z4mESZUverg&s=g3FrOYAsMPrmKtNPtyf91yfYH2zsmKMOmitLM8wZE1w&e=. >> com/v2/url?u=http-3A__www.R-2Dproject.org_&d=DwIBaQ&c=pZJPUD >> Q3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7 >> kQsdfEWUTu6qCGEw8Xuo91A&m=tRJQgGL9yUTACFh99WH_vy1dT68htuYJh- >> ugiZvUp_I&s=JxyBMGnGSSbvzgnGxb_rhGYCRWZG_3euARM8qQG7AjI&e= >> > posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > >> > This list strives to be beginner friendly. However, we still ask that >> you >> > PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=https-3A__urldefense.proofpoint&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=KOLF1vxBdafTXhLO69TErJDpzpSd4q69Z4mESZUverg&s=g3FrOYAsMPrmKtNPtyf91yfYH2zsmKMOmitLM8wZE1w&e=. >> com/v2/url?u=http-3A__www.R-2Dproject.org_&d=DwIBaQ&c=pZJPUD >> Q3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7 >> kQsdfEWUTu6qCGEw8Xuo91A&m=tRJQgGL9yUTACFh99WH_vy1dT68htuYJh- >> ugiZvUp_I&s=JxyBMGnGSSbvzgnGxb_rhGYCRWZG_3euARM8qQG7AjI&e= >> > posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > >> >> This list strives to be beginner friendly. However, we still ask that you >> PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posti&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=KOLF1vxBdafTXhLO69TErJDpzpSd4q69Z4mESZUverg&s=4ovnJ4K2j7Ku7EjEHRBaWpi5xixajvuD62JumZA6ANc&e= >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> This list strives to be beginner friendly. However, we still ask that you >> PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posti&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=KOLF1vxBdafTXhLO69TErJDpzpSd4q69Z4mESZUverg&s=4ovnJ4K2j7Ku7EjEHRBaWpi5xixajvuD62JumZA6ANc&e= >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> This list strives to be beginner friendly. However, we still ask that you >> PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posti&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=KOLF1vxBdafTXhLO69TErJDpzpSd4q69Z4mESZUverg&s=4ovnJ4K2j7Ku7EjEHRBaWpi5xixajvuD62JumZA6ANc&e= >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > This list strives to be beginner friendly. However, we still ask that you > PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwIFaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=qxljPB099KJTQNsmfps37CRdB4GQ4UsEkJdTfbyKaiE&s=nMpg8hVbLeOFq4lhOHJESRDiTMGaZMiAe2gu9vAsGy8&e= > and provide commented, minimal, self-contained, reproducible code. This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.```

2020
2019
2018
2017
2016
2015
2014
2013
2012
2011
2010
2009
2008