SB_
SB_

Reputation: 33

Derived table name in summary function in r

I have generated my model using

assign(paste("Model", MV1, sep = '') , glm(tv1 ~., family=binomial(link='logit'), 
                                           data=train70))

Now I would like to run the summary function on my output. I used the below code but rather then generating the co-efficents etc for my model I get a summary of a chracter variable. How do I tweak my code to run the summary for the model?

summary(paste("Model", MV1, sep = ''))

Upvotes: 0

Views: 69

Answers (1)

akuiper
akuiper

Reputation: 214927

You can use get function, which helps you evaluate the object with the name of a character. Here is a toy example:

x <- 1:10
y <- x + rnorm(10)
assign("model", lm(y ~ x))
summary(get("model"))

Call:
lm(formula = y ~ x)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.4863 -0.3476 -0.1218  0.2645  0.7806 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.01189    0.30979  -0.038     0.97    
x            0.93818    0.04993  18.791 6.65e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.4535 on 8 degrees of freedom
Multiple R-squared:  0.9778,    Adjusted R-squared:  0.9751 
F-statistic: 353.1 on 1 and 8 DF,  p-value: 6.646e-08

So for your case, summary(get(paste("Model", MV1, sep = ''))) should work for you.

Upvotes: 1

Related Questions