top of page

> x <- read.csv("数量化1.csv")
> x
   x1 x2    y
1   1  1  9.3
2   1  2  7.6
3   1  2 11.9
4   1  2 12.4
5   1  3 14.7
6   2  1 17.7
7   2  1 10.4
8   2  1 19.8
9   2  2 21.1
10  2  3 15.0
11  2  3 20.5
12  3  1 23.6
13  3  2 27.4
14  3  3 31.2
15  3  3 33.4


> attach(x)
> s1 <- lm(y~factor(x1)+factor(x2),data=x)
> summary(s1)

Call:
lm(formula = y ~ factor(x1) + factor(x2), data = x)

Residuals:
    Min      1Q  Median      3Q     Max 
-5.1162 -1.7025  0.6137  1.8075  4.3875 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)    8.669      2.267   3.824  0.00335 ** 
factor(x1)2    6.744      2.267   2.975  0.01392 *  
factor(x1)3   17.225      2.423   7.108 3.26e-05 ***
factor(x2)2    2.617      2.349   1.114  0.29128    
factor(x2)3    4.704      2.214   2.124  0.05959 .  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.427 on 10 degrees of freedom
Multiple R-squared:  0.8662,    Adjusted R-squared:  0.8127 
F-statistic: 16.19 on 4 and 10 DF,  p-value: 0.0002282


>#標準偏回帰係数(β)を求める
> lm.Beta3 = function(object) {
+   d = model.matrix(object$terms, eval(object$model, parent.frame()))
+   object$coefficients[-1] * apply(d[, -1, drop=FALSE], 2, sd) / sd(object$model[,1])
+ }
> lm.Beta3(s1)
factor(x1)2 factor(x1)3 factor(x2)2 factor(x2)3 
  0.4318276   0.9956292   0.1612812   0.2898286 

© 2018-2024 HIDEYUKI UNUMA

All visitors since 14 Apr. 2018

  • Twitter
  • Instagram
  • Facebook
bottom of page