podatki <- read.table("./Interakcije.csv", header=TRUE, sep=";", dec=",")
print(podatki)
##     Y X Spol
## 1   1 2    0
## 2   2 3    0
## 3   3 1    0
## 4   4 4    0
## 5   5 5    0
## 6   6 4    0
## 7   7 6    0
## 8   8 7    0
## 9   9 8    0
## 10 10 9    0
## 11  1 8    1
## 12  2 5    1
## 13  3 4    1
## 14  4 5    1
## 15  5 3    1

Opis kategorialne spremenljivke:

library(car)
scatterplot(y = podatki$Y, x = podatki$X, 
            main = "Y ~ X", 
            smooth = FALSE)

fit <- lm(Y ~ X, 
          data = podatki)

summary(fit)
## 
## Call:
## lm(formula = Y ~ X, data = podatki)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.9448 -1.1019  0.2838  1.7838  2.3123 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)   1.0018     1.4722   0.680   0.5082  
## X             0.7429     0.2718   2.733   0.0171 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.353 on 13 degrees of freedom
## Multiple R-squared:  0.3649, Adjusted R-squared:  0.316 
## F-statistic: 7.469 on 1 and 13 DF,  p-value: 0.01709
podatki$SpolF <- factor(podatki$Spol, 
                        levels = c(0, 1), 
                        labels = c("Z", "M"))

library(car)
scatterplot(Y ~ X | SpolF,
            main = "Y ~ X", 
            smooth = FALSE,
            data = podatki)

Ločena regresija za vsak spol

fit_z <- lm(Y ~ X, 
            data = podatki[podatki$SpolF == "Z", ])

summary(fit_z)
## 
## Call:
## lm(formula = Y ~ X, data = podatki[podatki$SpolF == "Z", ])
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.42529 -0.58621  0.06897  0.27586  1.75862 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.1494     0.7815   0.191    0.853    
## X             1.0920     0.1424   7.666 5.93e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.112 on 8 degrees of freedom
## Multiple R-squared:  0.8802, Adjusted R-squared:  0.8652 
## F-statistic: 58.77 on 1 and 8 DF,  p-value: 5.928e-05
fit_m <- lm(Y ~ X, 
            data = podatki[podatki$SpolF == "M", ])

summary(fit_m)
## 
## Call:
## lm(formula = Y ~ X, data = podatki[podatki$SpolF == "M", ])
## 
## Residuals:
##      11      12      13      14      15 
##  0.1429 -1.0000 -0.7143  1.0000  0.5714 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)   6.5714     1.3752   4.779   0.0174 *
## X            -0.7143     0.2608  -2.739   0.0714 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9759 on 3 degrees of freedom
## Multiple R-squared:  0.7143, Adjusted R-squared:  0.619 
## F-statistic:   7.5 on 1 and 3 DF,  p-value: 0.07142
fit <- lm(Y ~ X + SpolF, 
          data = podatki)

summary(fit)
## 
## Call:
## lm(formula = Y ~ X + SpolF, data = podatki)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.2630 -0.9105  0.6702  1.0808  3.5087 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)   1.8037     1.3222   1.364   0.1975   
## X             0.7543     0.2356   3.202   0.0076 **
## SpolFM       -2.5754     1.1169  -2.306   0.0398 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.039 on 12 degrees of freedom
## Multiple R-squared:  0.5599, Adjusted R-squared:  0.4865 
## F-statistic: 7.633 on 2 and 12 DF,  p-value: 0.007268
fit <- lm(Y ~ X + SpolF + X:SpolF, 
          data = podatki)

summary(fit)
## 
## Call:
## lm(formula = Y ~ X + SpolF + X:SpolF, data = podatki)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.4253 -0.6617  0.1149  0.4351  1.7586 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.1494     0.7567   0.197 0.847054    
## X             1.0920     0.1379   7.917 7.21e-06 ***
## SpolFM        6.4220     1.6949   3.789 0.003000 ** 
## X:SpolFM     -1.8062     0.3190  -5.662 0.000146 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.076 on 11 degrees of freedom
## Multiple R-squared:  0.8876, Adjusted R-squared:  0.8569 
## F-statistic: 28.95 on 3 and 11 DF,  p-value: 1.617e-05