LISTSERV mailing list manager LISTSERV 16.0

Help for R-USERS-L Archives


R-USERS-L Archives

R-USERS-L Archives


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

LISTSERV Archives

LISTSERV Archives

R-USERS-L Home

R-USERS-L Home

R-USERS-L  2018

R-USERS-L 2018

Subject:

Re: How to store result of coefficients from the model

From:

"Li,Daijiang" <[log in to unmask]>

Reply-To:

UF R Users List <[log in to unmask]>

Date:

Wed, 21 Feb 2018 14:29:59 +0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (155 lines)

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 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__cran.r-2Dproject.org_&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=tRJQgGL9yUTACFh99WH_vy1dT68htuYJh-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=http-3A__www.R-2Dproject.org_&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=tRJQgGL9yUTACFh99WH_vy1dT68htuYJh-ugiZvUp_I&s=JxyBMGnGSSbvzgnGxb_rhGYCRWZG_3euARM8qQG7AjI&e=
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> > <ask R.jpg>
>
> 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_&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&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_&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&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 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.

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.

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

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

ATOM RSS1 RSS2



LISTS.UFL.EDU

CataList Email List Search Powered by the LISTSERV Email List Manager