[R] turn regression coefficients into matrix or...
Jun Xu
mystata at hotmail.com
Tue Mar 13 17:52:19 CET 2007
Stephen, Norbert, Anup, and Mark, Thank you all for your help. With these
tips, I now have a much better understanding of the structure in R. Another
related question that has been haunting me is whether it is necessary to be
a convert from other statistical packages to R. Obviously, the great
advantage that R has is it's free and usually the newest stats technique is
first implemented in R. I had extensive experience with SAS and Stata, but I
really hate to keep investing int the never-satiated big financial abyss
there (e.g., various editions of manuals. However, I have some reservation
to be a convert as inertia always plays a big role if the utility is not
that big by switching from one software to another. What do you think?
>From: Stephen Tucker <brown_emu at yahoo.com>
>To: Norbert NEUWIRTH <norbertneuwirth at gmx.at>, Jun Xu <mystata at hotmail.com>
>CC: r-help at stat.math.ethz.ch
>Subject: Re: [R] turn regression coefficients into matrix or...
>Date: Tue, 13 Mar 2007 07:07:53 -0700 (PDT)
>
>I believe the short answer to your question lies in
>
> summary(ans.reg[[i]])$coefficients
>
>which will give you a matrix with coefficients and standard errors (and
>more). You can also find out what other information you can get from the
>regressions if you type
>
> attributes(ans.reg[[i]])
> attributes(summary(ans.reg[[i]]))
>
>and then see the names of the list elements (the regression functions and
>summary() return objects of mode "list") that might correspond to the
>information you are looking for.
>
>Good luck,
>
>ST
>
>
>
>
>--- Norbert NEUWIRTH <norbertneuwirth at gmx.at> wrote:
>
> > jun,
> >
> > im am also quite new to R. so i think, this is a question all we
>R-newbees
> >
> > ask ;-). having had the same "problem" the other day, i "solved" it the
> > following way:
> >
> > #### Multiple Regressions - Tables
> >
> > data(anscombe) # load anscombe
> > dataset (implemented somwhere in R)
> > x5 <- rnorm(11,14,1) # create an
>additional
> >
> > variable (at random)
> > anscombe.nn <- cbind(anscombe,x5) # attach the
>variable
> > to the dataset
> > attach(anscombe.nn) # attach the dataset
> > to the searchpath (just for convenience)
> > anscombe.nn # have a look on the
> > data
> >
> > ans.reg <- vector(4, mode = "list") # create empty list
> > (just for speeding up)
> >
> > for(i in 1:4){ # now the 4
> > regressions are stored to the list
> > j <- i+1
> > x1 <- get(paste("x", i, sep = "")) # exogenous var. #1
> > x2 <- get(paste("x", j, sep = "")) # exogenous var. #2
> > y <- get(paste("y", i, sep = "")) # endogenous
> > ans.reg[[i]] <- glm(y ~ x1+x2,family=gaussian) # do the regression
> > (out of 4)
> > print(summary(ans.reg[[i]],cor=FALSE))
> > }
> >
> > detach(anscombe) # detach dataset
>from
> > search path
> > lapply(ans.reg, coef) # see each
>regression
> > in one line
> > sapply(ans.reg, coef) # have the
> > coefficients in a table
> > x<-as.matrix(sapply(ans.reg, coef)) # convert table to
> > matrix
> > x
> >
> > this solution is quite comparable to Ligges(2007) [published in german
>and
> >
> > japanese, i think]
> >
> > i have an additional question to list-members, that have left the
> > newbee-status yet: how can i get R to hand over the standard errors,
> > significance levels etc, so that i can create a table with coeff and SE
> > and sig.?
> >
> > norbert
> >
> >
> > Am 13.03.2007, 02:58 Uhr, schrieb Jun Xu <mystata at hotmail.com>:
> >
> > > I don't have much experience with r. What I am trying to do is to turn
> > > regression coefficients (after I run a lm or glm model) into some
>matrix
> > > such that I can do some post-estimation calculation, for example
> > > predicted
> > > probabilities in glm model, etc.. Or, is there any function in r that
>I
> > > can
> > > use to do something along that line? thanks.
> > >
> > > Jun Xu, Ph.D.
> > > Department of Sociology
> > > Ball State University
> > >
> > > _________________________________________________________________
> > > Mortgage rates as low as 4.625% - Refinance $150,000 loan for $579 a
> > > month.
> > > Intro*Terms
> > >
> >
>https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h27f6&disc=y&vers=743&s=4056&p=5117
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> >
> >
> >
> > --
> > -------------------------------
> > Mag. Norbert NEUWIRTH
> >
> > Roubiczekgasse 2/23
> > A-1100 WIEN
> > mob: +43 699 1835 0704
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>
>
>____________________________________________________________________________________
>Food fight? Enjoy some healthy debate
>in the Yahoo! Answers Food & Drink Q&A.
>http://answers.yahoo.com/dir/?link=list&sid=396545367
_________________________________________________________________
With tax season right around the corner, make sure to follow these few
simple tips.
More information about the R-help
mailing list