-1

I am working in an analytical lab where a lot of data is generated. We do model fitting and are interested in model coefficients (intercept, a, b), r_squared and residual standard error. The number of up to 70 dependant variables (responses) is rather large. I would like to generate from mylms a table where the rows are the responses a to f and the columns the mentioned model parameters.

I was not able to adapt the solutions I found on the net to my case:

A part of the solution is surely summary(mylms) where the parameters are stored.

Here is the simplified example I would like to find a solution to:

#To generate a dataset
x <- c(1:30)
x2 <- x*x
a <- x2
b <- jitter(a, factor=10)
c <- jitter(b, factor=30)
d <- jitter(c, factor=40)
e <- jitter(d, factor=50)
f <- jitter(e, factor=60)
z <- cbind(a,b,c,d,e,f)

# The matrix y are the responses of x
y <- as.matrix(z)

# Define the weights for the regression
w <- 1/x

# create linear models
mylms <- lm(y~x+x2, weights=w)
Community
  • 1
  • 1
ThomasG
  • 1
  • 1
  • so you have up to 70 columns, where the fields are the coefficients? And how many rows do you have? Always 6 (A-F)? – Simon Apr 08 '16 at 02:12
  • 1
    Check out the broom package: https://cran.r-project.org/web/packages/broom/index.html – Rob Hyndman Apr 08 '16 at 02:28
  • Actually, in my response matrix y the number of colums will change. It might be 30, but it might also be 70 or 15. The number of columns in matrix y will equal the number of rows in my result table. But the result table will always have 5 rows: intercept, a, b, r_squared and residual standard error. – ThomasG Apr 08 '16 at 05:59
  • When I use glance I get this error: glance does not support multiple responses I managed to get the coefficients by the tidy function! :) – ThomasG Apr 09 '16 at 20:10
  • Rob, could you provide the code for the solution, please? – ThomasG Apr 09 '16 at 20:27

1 Answers1

0

You can do this:

mylms$residuals

or to get the range of the residuals for example:

apply(mylms$residuals,2,range)

or to get the quantiles for example:

apply(mylms$residuals,2,quantile,seq(0.1,0.9,by=0.1))
dur
  • 15,689
  • 25
  • 79
  • 125
  • Actually I am looking for the residual standard error, not each residual itself! – ThomasG Apr 11 '16 at 19:54
  • I found the solution Rest.stabw <- NULL R2 <- NULL for(i in 1:l/2){ Rest.stabw[i] <- summary(mylms)[[i]]$sigma R2[i] <- summary(a.lm)[[i]]$r.squared } – ThomasG May 21 '16 at 05:16