[R] turn regression coefficients into matrix or...
Stephen Tucker
brown_emu at yahoo.com
Tue Mar 13 15:07:53 CET 2007
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
More information about the R-help
mailing list