robertevansanders - 11 days ago 5

R Question

I have many interaction terms, and I want to have the name of these coefficients, which will be output to LaTeX, not be so cumbersome.

I do not want to generate all the interactions in my data frame beforehand, that is a big nuisance.

Answer

Not sure if you just mean change the names, but if so this is how you do that.

```
a <- runif(100,0,100)
b <- 3*a+runif(100,0,50)
c <- 4*a+runif(100,0,60)
fit <- lm(a~b+c)
names(fit$coefficients) <- c('bob','sally','sue')
summary(fit)
# Call:
#lm(formula = a ~ b + c)
#
#Residuals:
# Min 1Q Median 3Q Max
#-5.8876 -2.0380 0.0111 1.6112 6.4377
#
#Coefficients:
# Estimate Std. Error t value Pr(>|t|)
#bob -8.72283 0.68552 -12.72 <2e-16 ***
#sally 0.15337 0.01484 10.33 <2e-16 ***
#sue 0.13740 0.01110 12.38 <2e-16 ***
#---
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
#Residual standard error: 2.945 on 97 degrees of freedom
#Multiple R-squared: 0.9893, Adjusted R-squared: 0.9891
#F-statistic: 4472 on 2 and 97 DF, p-value: < 2.2e-16
```

Source (Stackoverflow)

Comments