User Tools

Site Tools


r:dummy_variables_with_significant_interaction

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
r:dummy_variables_with_significant_interaction [2023/06/02 01:26] hkimscilr:dummy_variables_with_significant_interaction [2023/06/05 22:01] (current) – [Regression with a continous + a categorical variables: ANCOVA] hkimscil
Line 1: Line 1:
 +====== Regression with two categorical variables (IVs): Two way anova  ======
 +https://advstats.psychstat.org/book/mregression/catpredictor.php#example-4-regression-with-one-categorical-and-one-continuous-predictors-ancova
 <code> <code>
 college <- read.csv("http://commres.net/wiki/_media/r/college.csv") college <- read.csv("http://commres.net/wiki/_media/r/college.csv")
Line 18: Line 20:
 a.m2 <- aov(salary~public*location) a.m2 <- aov(salary~public*location)
 summary(a.m2) summary(a.m2)
 +
 +interaction.plot(x.factor = location,
 +                 trace.factor = public,
 +                 response = salary,
 +                 fun = median, 
 +                 ylab = "salary", 
 +                 xlab = "location", 
 +                 col=c("red", "blue"),
 +                 lty = 1, 
 +                 lwd=2, 
 +                 trace.label="public")
 </code> </code>
 +====== output ======
 <code> <code>
 #################### ####################
Line 111: Line 125:
 --- ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +>
 +> interaction.plot(x.factor = location,
 ++                  trace.factor = public,
 ++                  response = salary,
 ++                  fun = median, 
 ++                  ylab = "salary", 
 ++                  xlab = "location", 
 ++                  col=c("red", "blue"),
 ++                  lty = 1, 
 ++                  lwd=2, 
 ++                  trace.label="public")
  
 </code> </code>
 +{{:r:pasted:20230602-013149.png}}
 +
 +====== Regression with a continous + a categorical variables: ANCOVA ======
 +<code>
 +summary(mod<-lm(salary~cost + location))
 +anova(mod)
 +</code>
 +
 +<code>
 +> summary(mod<-lm(salary~cost + location))
 +
 +Call:
 +lm(formula = salary ~ cost + location)
 +
 +Residuals:
 +    Min      1Q  Median      3Q     Max 
 +-20.244  -4.933  -0.572   3.162  29.939 
 +
 +Coefficients:
 +             Estimate Std. Error t value Pr(>|t|)    
 +(Intercept)  8.78e+01   3.10e+00   28.34  < 2e-16 ***
 +cost         6.05e-05   1.73e-05    3.50  0.00076 ***
 +locationMW  -2.80e+00   2.57e+00   -1.09  0.27885    
 +locationNE   9.23e+00   2.42e+00    3.81  0.00027 ***
 +locationW   -1.05e+01   2.57e+00   -4.10  0.00010 ***
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 8.02 on 80 degrees of freedom
 +Multiple R-squared:  0.571, Adjusted R-squared:  0.549 
 +F-statistic: 26.6 on 4 and 80 DF,  p-value: 4.96e-14
 +
 +> anova(mod)
 +Analysis of Variance Table
 +
 +Response: salary
 +          Df Sum Sq Mean Sq F value  Pr(>F)    
 +cost         2757    2757    42.9 5.1e-09 ***
 +location     4072    1357    21.1 3.6e-10 ***
 +Residuals 80   5141      64                    
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +</code>
 +
 +<code>
 +(Intercept)  8.78e+01   3.10e+00   28.34  < 2e-16 ***
 +cost         6.05e-05   1.73e-05    3.50  0.00076 ***
 +locationMW  -2.80e+00   2.57e+00   -1.09  0.27885    
 +locationNE   9.23e+00   2.42e+00    3.81  0.00027 ***
 +locationW   -1.05e+01   2.57e+00   -4.10  0.00010 ***
 +
 +</code>
 +
 +''y hat ~ 87.8 + .00006*cost - 2.8 MW + 9.23 NE - 10.5 E ''
 +
 +  * S, MW, NE, W 중에서 S가 default
 +    * y hat ~ 87.8 + .00006*cost
 +  * MW: 
 +    * y hat ~ 87.8 - 2.8 + .00006*cost
 +    * y hat ~ 85 + .00006*cost
 +  * NE:
 +    * y hat ~ 87.8 - 9.23 + .00006*cost
 +    * y hat ~ 78.57 + .00006*cost
 +  * E:
 +    * y hat ~ 87.8 - 10.5 + .00006*cost
 +    * y hat ~ 77.3 + .00006*cost
 +
 +<code>
 +> summary(mod2<-lm(salary~cost * location))
 +
 +Call:
 +lm(formula = salary ~ cost * location)
 +
 +Residuals:
 +     Min       1Q   Median       3Q      Max 
 +-17.1126  -5.6241  -0.8152   2.6401  28.4861 
 +
 +Coefficients:
 +                  Estimate Std. Error t value Pr(>|t|)    
 +(Intercept)      8.863e+01  4.995e+00  17.744   <2e-16 ***
 +cost             5.480e-05  3.211e-05   1.707   0.0919 .  
 +locationMW      -5.526e+00  7.213e+00  -0.766   0.4460    
 +locationNE      -2.866e+00  7.383e+00  -0.388   0.6989    
 +locationW       -1.876e+00  6.509e+00  -0.288   0.7740    
 +cost:locationMW  1.885e-05  4.681e-05   0.403   0.6882    
 +cost:locationNE  7.480e-05  4.533e-05   1.650   0.1030    
 +cost:locationW  -7.815e-05  4.665e-05  -1.675   0.0980 .  
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 7.644 on 77 degrees of freedom
 +Multiple R-squared:  0.6241, Adjusted R-squared:  0.5899 
 +F-statistic: 18.26 on 7 and 77 DF,  p-value: 4.313e-14
 +
 +> anova(mod2)
 +Analysis of Variance Table
 +
 +Response: salary
 +              Df Sum Sq Mean Sq F value    Pr(>F)    
 +cost           1 2757.0 2756.97  47.183 1.470e-09 ***
 +location       3 4071.8 1357.26  23.228 8.276e-11 ***
 +cost:location  3  641.6  213.86   3.660   0.01596 *  
 +Residuals     77 4499.2   58.43                      
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +</code>
 +
 +
r/dummy_variables_with_significant_interaction.1685636777.txt.gz · Last modified: 2023/06/02 01:26 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki