library(rio)
library(foreign)
library(haven)
library(dplyr)
## 
## Присоединяю пакет: 'dplyr'
## Следующие объекты скрыты от 'package:stats':
## 
##     filter, lag
## Следующие объекты скрыты от 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(knitr)
library(kableExtra)
## 
## Присоединяю пакет: 'kableExtra'
## Следующий объект скрыт от 'package:dplyr':
## 
##     group_rows
library(tidyr)
library(vtable)
library(table1)
## 
## Присоединяю пакет: 'table1'
## Следующие объекты скрыты от 'package:base':
## 
##     units, units<-
library(sjPlot)
library(dplyr)
library(data.table)
## 
## Присоединяю пакет: 'data.table'
## Следующие объекты скрыты от 'package:dplyr':
## 
##     between, first, last
library(kableExtra)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ lubridate 1.9.3     ✔ stringr   1.5.1
## ✔ purrr     1.0.2     ✔ tibble    3.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ data.table::between()    masks dplyr::between()
## ✖ dplyr::filter()          masks stats::filter()
## ✖ data.table::first()      masks dplyr::first()
## ✖ kableExtra::group_rows() masks dplyr::group_rows()
## ✖ lubridate::hour()        masks data.table::hour()
## ✖ lubridate::isoweek()     masks data.table::isoweek()
## ✖ dplyr::lag()             masks stats::lag()
## ✖ data.table::last()       masks dplyr::last()
## ✖ lubridate::mday()        masks data.table::mday()
## ✖ lubridate::minute()      masks data.table::minute()
## ✖ lubridate::month()       masks data.table::month()
## ✖ lubridate::quarter()     masks data.table::quarter()
## ✖ lubridate::second()      masks data.table::second()
## ✖ purrr::transpose()       masks data.table::transpose()
## ✖ lubridate::wday()        masks data.table::wday()
## ✖ lubridate::week()        masks data.table::week()
## ✖ lubridate::yday()        masks data.table::yday()
## ✖ lubridate::year()        masks data.table::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readr)
library(ggplot2)
library(knitr)
library(magrittr)
## 
## Присоединяю пакет: 'magrittr'
## 
## Следующий объект скрыт от 'package:purrr':
## 
##     set_names
## 
## Следующий объект скрыт от 'package:tidyr':
## 
##     extract
library(gridExtra)
## 
## Присоединяю пакет: 'gridExtra'
## 
## Следующий объект скрыт от 'package:dplyr':
## 
##     combine
library(car)
## Загрузка требуемого пакета: carData
## 
## Присоединяю пакет: 'car'
## 
## Следующий объект скрыт от 'package:purrr':
## 
##     some
## 
## Следующий объект скрыт от 'package:dplyr':
## 
##     recode
library(psych)
## 
## Присоединяю пакет: 'psych'
## 
## Следующий объект скрыт от 'package:car':
## 
##     logit
## 
## Следующие объекты скрыты от 'package:ggplot2':
## 
##     %+%, alpha
library(carData)
library(scales)
## 
## Присоединяю пакет: 'scales'
## 
## Следующие объекты скрыты от 'package:psych':
## 
##     alpha, rescale
## 
## Следующий объект скрыт от 'package:purrr':
## 
##     discard
## 
## Следующий объект скрыт от 'package:readr':
## 
##     col_factor
library(DescTools)
## 
## Присоединяю пакет: 'DescTools'
## 
## Следующие объекты скрыты от 'package:psych':
## 
##     AUC, ICC, SD
## 
## Следующий объект скрыт от 'package:car':
## 
##     Recode
## 
## Следующий объект скрыт от 'package:data.table':
## 
##     %like%
db <- import("C:/Users/DP/Downloads/F00011356-WVS_Cross-National_Wave_7_csv_v5_0//WVS_Cross-National_Wave_7_csv_v5_0.csv")

Manipulating the Data

Select observations from Cyprus

db <- filter(db, B_COUNTRY=="196")

I will keep only the variables necessary for further analysis.

db <- select(db, Q206, Q260,Q262, Q275R, Y001, Q186)

Justification of sexual relationship before marriage (Q186)

Значения переменной из codebook:

1.- Never justifiable 2.- 2 3.- 3 4.- 4 5.- 5 6.- 6 7.- 7 8.- 8 9.- 9 10.- Always justifiable

-1-.- Don´t know -2-.- No answer -4-.- Not asked in survey -5-.- Missing; Not available

Accordingly, I will recode -1, -2, -4, and -5 as NA so that these values do not affect the results of further analysis.

db$Q186[db$Q186 == -5 | db$Q186 == -4 | db$Q186 == -3 | db$Q186 == -2 | db$Q186 == -1] <- NA

Changing the name of the variable for convenient use in the analysis

names(db)[names(db) == "Q186"] <- "sex_bef_mar"

Encoding the variable as numeric

db$sex_bef_mar <- as.numeric(db$sex_bef_mar)

Age (Q262)

Variable values from codebook:

Numeric variable – numbers of years -1-.- Don’t know -2-.- No answer -4-.- Not asked -5-.- Missing; Not available

db$Q262[db$Q262 == -5 | db$Q262 == -4 | db$Q262 == -3 | db$Q262 == -2 | db$Q262 == -1] <- NA

Changing the name of the variable for convenient use in the analysis

names(db)[names(db) == "Q262"] <- "age"

Encoding the variable as numeric

db$age <- as.numeric(db$age)

Gender (Q260)

Variable values from codebook: 1.- Male 2.- Female -2-.- No answer -4-.- Not asked -5-.- Missing; Not available; AU: Other

db$Q260[db$Q260 == -5 | db$Q260 == -4 | db$Q260 == -2 ] <- NA

Changing the name of the variable for convenient use in the analysis

names(db)[names(db) == "Q260"] <- "gndr"

I change the value of 1 to male, and the value of 2 to female to make it easier to work with the variable

db$gndr <- factor(db$gndr, levels = c(1, 2), labels = c("male", "female"))

Encoding the variable as a factor

db$gndr <- factor(db$gndr)

highest educational level (3 groups) (Q275R)

Variable values from codebook: 1.- Lower 2.- Middle 3.- Higher -1-.- Don´t know -2-.- No answer -4-.- Not asked -5-.- Missing; Not available

db$Q275R[db$Q275R == -5 | db$Q275R == -4 | db$Q275R == -2 | db$Q275R == -1 ] <- NA

Changing the name of the variable for convenient use in the analysis

names(db)[names(db) == "Q275R"] <- "educ_lvl"

I change the value 1 to lower, 2 to middle, 3 to higher to make it easier to work with the variable

db$educ_lvl <- factor(db$educ_lvl, levels = c(1, 2, 3), labels = c("lower", "middle", "higher"))

frequency of Internet use as a source of information (Q206)

Variable values from codebook:

1.- Daily 2.- Weekly 3.- Monthly 4.- Less than monthly 5.- Never -1-.- Don´t know -2-.- No answer -4-.- Not asked -5-.- Missing; Not available

db$Q206[db$Q206 == -5 | db$Q206 == -4 | db$Q206 == -2 | db$Q206 == -1 ] <- NA

Changing the name of the variable for convenient use in the analysis

names(db)[names(db) == "Q206"] <- "int_use"

I change the value 1 to daily, 2 to weekly, 3 to monthly, 4 to less than monthly, 5 to never to make it easier to work with the variable

db$int_use <- factor(db$int_use, levels = c(1, 2, 3, 4, 5), labels = c("daily", "weekly", "monthly", "less than monthly", "never"))

12-item index of postmaterialism (Y001)

Variable values from codebook:

if Y001_1>-2 and Y001_2>-2 and Y001_3>-2 and Y001_4>-2 and Y001_5>-2 THEN Y001_1+Y001_2+Y001_3+Y001_4+Y001_5 else -2

db$Y001[db$Y001 == -2 ] <- NA

Changing the name of the variable for convenient use in the analysis

names(db)[names(db) == "Y001"] <- "ind_mat"

Encoding the variable as numeric

db$ind_mat <- as.numeric(db$ind_mat)

Checking the types of variables

class(db$int_use)
## [1] "factor"
class(db$gndr)
## [1] "factor"
class(db$age)
## [1] "numeric"
class(db$educ_lvl)
## [1] "factor"
class(db$ind_mat)
## [1] "numeric"
class(db$sex_bef_mar)
## [1] "numeric"

Creating a beautiful table :)

db <- na.omit(db)
label(db$int_use) = 'frequency of Internet use'
label(db$gndr) = 'gender'
label(db$age) = 'age'
label(db$educ_lvl) = 'highest educational level'
label(db$ind_mat) = 'index of postmaterialism'
label(db$sex_bef_mar) = 'justification of sexual relationship before marriage'

t1kable(table1(~int_use + gndr + age + educ_lvl + ind_mat + sex_bef_mar, data = db))%>%
  kable_styling(font_size = 16)
  Overall
(N=824)
frequency of Internet use
daily 483 (58.6%)
weekly 113 (13.7%)
monthly 26 (3.2%)
less than monthly 18 (2.2%)
never 184 (22.3%)
gender
male 401 (48.7%)
female 423 (51.3%)
age
Mean (SD) 43.7 (16.2)
Median [Min, Max] 42.0 [18.0, 92.0]
highest educational level
lower 182 (22.1%)
middle 228 (27.7%)
higher 414 (50.2%)
index of postmaterialism
Mean (SD) 2.31 (1.25)
Median [Min, Max] 2.00 [0, 5.00]
justification of sexual relationship before marriage
Mean (SD) 5.26 (3.15)
Median [Min, Max] 5.00 [1.00, 10.0]

Seems relatively legit, now I need to understand our variables from our dataset graphically.

Graphical representation of variables

For that i will need to create:

  • Box plot, to show the continuous variables and spot outliers.

  • Density plot, to check if the distribution of our continuous variables is close to normal.

  • Barplot, to see if the categoricalal variables are representative.

  • Scatter plot, to visualize the linear relationship between the variables.

Boxplot to check for outliers

db %>% 
  pivot_longer(c(age, ind_mat, sex_bef_mar),
               names_to = 'Var', values_to = 'Score') %>% 
  ggplot(aes(y = Score)) + 
  geom_boxplot() +
  ggtitle("Distribution of scores") +
  xlab("Variable") + 
  ylab("Score") +
  theme_bw() +
  theme(legend.position = "none") +
  facet_wrap(~Var, scales = 'free')

It can be seen that there are no outliers

Histograms to check if continuous variables are close to normal

db %>% 
  pivot_longer(c(age, ind_mat, sex_bef_mar),
               names_to = 'Var', values_to = 'Score') %>% 
  ggplot(aes(x=Score, fill=Var)) + 
  geom_histogram(aes(y=..density.., fill = Var), bins = 10) +
  geom_density(alpha = .5, color="blue")+
  ggtitle("Distribution of scores") +
  xlab("Variable") + 
  ylab("Score") +
  theme_bw()+
  theme(legend.position="none") +
  facet_wrap(~Var, scales = 'free')
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

As it can be seen from the histograms, ind_mat is slightly close to normal distribution. As for sex_bef_mar and age , the histograms are not normally distributed. However, I can surely work with that.

Barplots to check if categorical variables are representative

db %>% 
  ggplot(aes(x = gndr)) +
  geom_bar(fill = "lightpink", color = "lightblue") +
  xlab("Category") +
  ylab("Frequency") +
  theme_bw() 

I see that the groups are comparable in size, there are slightly more female than male

db %>% 
  ggplot(aes(x = int_use)) +
  geom_bar(fill = "lightpink", color = "lightblue") +
  xlab("Category") +
  ylab("Frequency") +
  theme_bw() 

prop.table(table(db$int_use))
## 
##             daily            weekly           monthly less than monthly 
##        0.58616505        0.13713592        0.03155340        0.02184466 
##             never 
##        0.22330097

You can see that the data is not of comparable size, it is better to combine some categories so that they are approximately the same size. So, if I combine the smallest categories (weekly, monthly, less than monthly) into the category rarely, I get the following:

db$int_use <- ifelse(db$int_use %in% c("weekly", "monthly", "less than monthly"), "rarely", 
                     ifelse(db$int_use == "daily", "daily", 
                            ifelse(db$int_use == "never", "never", NA)))
prop.table(table(db$int_use))
## 
##    daily    never   rarely 
## 0.586165 0.223301 0.190534
db %>% 
  ggplot(aes(x = int_use)) +
  geom_bar(fill = "lightpink", color = "lightblue") +
  xlab("Category") +
  ylab("Frequency") +
  theme_bw() 

The groups have become more comparable in size

db %>% 
  ggplot(aes(x = educ_lvl)) +
  geom_bar(fill = "lightpink", color = "lightblue") +
  xlab("Category") +
  ylab("Frequency") +
  theme_bw() 

prop.table(table(db$educ_lvl))
## 
##     lower    middle    higher 
## 0.2208738 0.2766990 0.5024272

I can see that the data is not very comparable, but I can use

Using Scatterplots to visualise the relationship

plot = ggplot(data = db, aes(x = age, y = ind_mat)) + geom_point() + geom_smooth(method = lm, fill="blue", color="blue", se = FALSE)  + ggtitle("Age by index of postmaterialism") + xlab("Age") + ylab("index of postmaterialism")
plot
## `geom_smooth()` using formula = 'y ~ x'

there is a negative correlation between age and ind_mat

plot1 = ggplot(data = db, aes(x = age, y = sex_bef_mar)) + geom_point() + geom_smooth(method = lm, fill="blue", color="blue", se = FALSE)  + ggtitle("Age by justification of sexual relationship before marriage") + xlab("Age") + ylab("justification of sexual relationship before marriage")
plot1
## `geom_smooth()` using formula = 'y ~ x'

very weak negative relationship between age and sex_bef_mr

plot2 = ggplot(data = db, aes(x = ind_mat, y = sex_bef_mar)) + geom_point() + geom_smooth(method = lm, fill="blue", color="blue", se = FALSE)  + ggtitle("Iindex of postmaterialism by justification of sexual relationship before marriage") + xlab("index of postmaterialism") + ylab("justification of sexual relationship before marriage")
plot2
## `geom_smooth()` using formula = 'y ~ x'

there is a rather weak negative relationship between age and sex_bef_mr

library(heatmaply)
## Загрузка требуемого пакета: plotly
## 
## Присоединяю пакет: 'plotly'
## Следующий объект скрыт от 'package:ggplot2':
## 
##     last_plot
## Следующий объект скрыт от 'package:rio':
## 
##     export
## Следующий объект скрыт от 'package:stats':
## 
##     filter
## Следующий объект скрыт от 'package:graphics':
## 
##     layout
## Загрузка требуемого пакета: viridis
## Загрузка требуемого пакета: viridisLite
## 
## Присоединяю пакет: 'viridis'
## Следующий объект скрыт от 'package:scales':
## 
##     viridis_pal
## Registered S3 methods overwritten by 'registry':
##   method               from 
##   print.registry_field proxy
##   print.registry_entry proxy
## 
## ======================
## Welcome to heatmaply version 1.5.0
## 
## Type citation('heatmaply') for how to cite the package.
## Type ?heatmaply for the main documentation.
## 
## The github page is: https://github.com/talgalili/heatmaply/
## Please submit your suggestions and bug-reports at: https://github.com/talgalili/heatmaply/issues
## You may ask questions at stackoverflow, use the r and heatmaply tags: 
##   https://stackoverflow.com/questions/tagged/heatmaply
## ======================
heatmaply_cor(
  cor(db[,c('ind_mat', 'sex_bef_mar', 'age')], method = "spearman"),
  Colv=NA, Rowv=NA)

From what I can see, all the relationships between our variables are quite insignificant and have a negative orientation. What is interesting, that the highest correlation coefficient is between age and ind_mat. The presented values confirm the situation on the scatterplots.

Linear Regression Models

Estimate a model to predict justification of sexual relationship before marriage (Q186) by age (Q262), gender (Q260), highest educational level (3 groups) (Q275R), frequency of Internet use as a source of information (Q206), 12-item index of postmaterialism (Y001), as well as an interaction between age and gender (1 point).

Standardizing variables to improve the model

db <- db %>% 
  mutate(Zage = scale(age)[,1],
         Zsex_bef_mar = scale(sex_bef_mar)[,1],
         Zind_mat = scale(ind_mat)[,1])

Model1

model1 = lm(Zsex_bef_mar ~  educ_lvl + int_use + Zind_mat + Zage * gndr, data = db)
summary(model1)
## 
## Call:
## lm(formula = Zsex_bef_mar ~ educ_lvl + int_use + Zind_mat + Zage * 
##     gndr, data = db)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.85663 -0.88954  0.03154  0.76192  1.95172 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)   
## (Intercept)      0.06898    0.10695   0.645  0.51915   
## educ_lvlmiddle   0.26994    0.10765   2.508  0.01235 * 
## educ_lvlhigher  -0.13089    0.11202  -1.168  0.24298   
## int_usenever    -0.29839    0.11184  -2.668  0.00778 **
## int_userarely   -0.28243    0.09028  -3.128  0.00182 **
## Zind_mat        -0.04262    0.03473  -1.227  0.22011   
## Zage             0.10664    0.05599   1.904  0.05721 . 
## gndrfemale       0.07720    0.06847   1.127  0.25991   
## Zage:gndrfemale -0.19422    0.06938  -2.799  0.00524 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9769 on 815 degrees of freedom
## Multiple R-squared:  0.05488,    Adjusted R-squared:  0.0456 
## F-statistic: 5.916 on 8 and 815 DF,  p-value: 2.207e-07
sjPlot::tab_model(model1)
  Zsex_bef_mar
Predictors Estimates CI p
(Intercept) 0.07 -0.14 – 0.28 0.519
highest educational
level: middle
0.27 0.06 – 0.48 0.012
highest educational
level: higher
-0.13 -0.35 – 0.09 0.243
int_usenever -0.30 -0.52 – -0.08 0.008
int_userarely -0.28 -0.46 – -0.11 0.002
Zind_mat -0.04 -0.11 – 0.03 0.220
Zage 0.11 -0.00 – 0.22 0.057
gender: female 0.08 -0.06 – 0.21 0.260
Zage:gndrfemale -0.19 -0.33 – -0.06 0.005
Observations 824
R2 / R2 adjusted 0.055 / 0.046

Explanation model1

Significant coefficients: If the respondent has a middle level of education, then the indicator of justification sex before the marriage increases by 0.27 If the respondent has never used the Internet, the indicator of justification sex before the marriage decreases by 0.30 If the respondent rarely used the Internet, the indicator of justification sex before the marriage decreases by -0.28

In the model the interaction effect between age (Zage) and gender (gndr) on the dependent variable Zsex_bef_mar. The coefficient of -0.19 suggests that for females, for each one-unit increase in age, the predicted value of Zsex_bef_mar decreases by approximately 0.19 units on average. The p-value of 0.005 suggests that this interaction effect is statistically significant, indicating that the relationship between age and Zsex_bef_mar significantly differs between genders. Specifically, the negative coefficient suggests that as females get older, their attitude towards premarital sex tends to decrease more compared to males.

Insignificant coefficients: The coefficients for the variables educ_lvlhigher, Zind_mat, Zage, and gndrfemale are not statistically significant at the 0.05 level.

The multiple R-squared is 0.055, indicating that approximately 5.5% of the variance in the dependent variable is explained by the predictors used. The adjusted R-squared is 0.046.

The F-statistic is 5.916, and the p-value is less than 0.001 (2.207e-07), indicating that the model1 as a whole is statistically significant.

Linear Regression Assumptions model1

2.1 Non-linearity 2.2 Residual distribution 2.3 Heteroscedasticity 2.4 Multicollinearity 2.5 Outliers

par(mfrow = c(2, 2))
plot(model1)

Linearity assumption: at the Residuals vs.Fitted plot a horizontal line, without distinct patterns can be seen, which is surely a good thing. (Our data is linear)

The Q-Q plot shows deviations of residues from both one and the other sides of a straight line (that is, the points of residues are not evenly spaced on both sides of the line), this may be evidence of an abnormal distribution of residues.

Scale-Location & Residuals vs. Leverage plot show us a red horizontal line with equally spread points. This corresponds with the homoscedasticity of our data.

On Residuals vs Leverage plot I can spot only a couple of outliers

Checking Multicollinearity

vif(model1, type = 'predictor')
## GVIFs computed for predictors
##              GVIF Df GVIF^(1/(2*Df)) Interacts With
## educ_lvl 1.694660  2        1.140961           --  
## int_use  1.764996  2        1.152619           --  
## Zind_mat 1.040038  1        1.019823           --  
## Zage     1.925850  3        1.115417           gndr
## gndr     1.925850  3        1.115417           Zage
##                        Other Predictors
## educ_lvl  int_use, Zind_mat, Zage, gndr
## int_use  educ_lvl, Zind_mat, Zage, gndr
## Zind_mat  educ_lvl, int_use, Zage, gndr
## Zage        educ_lvl, int_use, Zind_mat
## gndr        educ_lvl, int_use, Zind_mat

Multicollinearity отсутствует

summary(model1)
## 
## Call:
## lm(formula = Zsex_bef_mar ~ educ_lvl + int_use + Zind_mat + Zage * 
##     gndr, data = db)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.85663 -0.88954  0.03154  0.76192  1.95172 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)   
## (Intercept)      0.06898    0.10695   0.645  0.51915   
## educ_lvlmiddle   0.26994    0.10765   2.508  0.01235 * 
## educ_lvlhigher  -0.13089    0.11202  -1.168  0.24298   
## int_usenever    -0.29839    0.11184  -2.668  0.00778 **
## int_userarely   -0.28243    0.09028  -3.128  0.00182 **
## Zind_mat        -0.04262    0.03473  -1.227  0.22011   
## Zage             0.10664    0.05599   1.904  0.05721 . 
## gndrfemale       0.07720    0.06847   1.127  0.25991   
## Zage:gndrfemale -0.19422    0.06938  -2.799  0.00524 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9769 on 815 degrees of freedom
## Multiple R-squared:  0.05488,    Adjusted R-squared:  0.0456 
## F-statistic: 5.916 on 8 and 815 DF,  p-value: 2.207e-07

Model2

Let’s try to improve the model by squaring

db <- db %>% 
  mutate(Zage_sq = Zage^2,
         Zsex_bef_mar_sq = Zsex_bef_mar^2,
         Zind_mat_sq = Zind_mat^2)

model2 <- lm(Zsex_bef_mar ~ educ_lvl + int_use + Zind_mat + Zage * gndr + Zage_sq + Zsex_bef_mar_sq + Zind_mat_sq, data = db)

summary(model2)
## 
## Call:
## lm(formula = Zsex_bef_mar ~ educ_lvl + int_use + Zind_mat + Zage * 
##     gndr + Zage_sq + Zsex_bef_mar_sq + Zind_mat_sq, data = db)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.1276 -0.8996  0.1045  0.7866  1.9599 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     -0.03416    0.12521  -0.273 0.785047    
## educ_lvlmiddle   0.29556    0.10673   2.769 0.005745 ** 
## educ_lvlhigher  -0.10829    0.11103  -0.975 0.329684    
## int_usenever    -0.39983    0.11553  -3.461 0.000567 ***
## int_userarely   -0.26113    0.09010  -2.898 0.003854 ** 
## Zind_mat        -0.03198    0.03450  -0.927 0.354228    
## Zage             0.10296    0.05561   1.851 0.064471 .  
## gndrfemale       0.08259    0.06790   1.216 0.224187    
## Zage_sq          0.10918    0.03771   2.895 0.003891 ** 
## Zsex_bef_mar_sq  0.07415    0.03895   1.904 0.057281 .  
## Zind_mat_sq     -0.08244    0.02846  -2.897 0.003872 ** 
## Zage:gndrfemale -0.17842    0.06883  -2.592 0.009704 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9668 on 812 degrees of freedom
## Multiple R-squared:  0.07775,    Adjusted R-squared:  0.06525 
## F-statistic: 6.223 on 11 and 812 DF,  p-value: 6.748e-10
sjPlot::tab_model(model1, model2)
  Zsex_bef_mar Zsex_bef_mar
Predictors Estimates CI p Estimates CI p
(Intercept) 0.07 -0.14 – 0.28 0.519 -0.03 -0.28 – 0.21 0.785
highest educational
level: middle
0.27 0.06 – 0.48 0.012 0.30 0.09 – 0.51 0.006
highest educational
level: higher
-0.13 -0.35 – 0.09 0.243 -0.11 -0.33 – 0.11 0.330
int_usenever -0.30 -0.52 – -0.08 0.008 -0.40 -0.63 – -0.17 0.001
int_userarely -0.28 -0.46 – -0.11 0.002 -0.26 -0.44 – -0.08 0.004
Zind_mat -0.04 -0.11 – 0.03 0.220 -0.03 -0.10 – 0.04 0.354
Zage 0.11 -0.00 – 0.22 0.057 0.10 -0.01 – 0.21 0.064
gender: female 0.08 -0.06 – 0.21 0.260 0.08 -0.05 – 0.22 0.224
Zage:gndrfemale -0.19 -0.33 – -0.06 0.005 -0.18 -0.31 – -0.04 0.010
Zage_sq 0.11 0.04 – 0.18 0.004
Zsex_bef_mar_sq 0.07 -0.00 – 0.15 0.057
Zind_mat_sq -0.08 -0.14 – -0.03 0.004
Observations 824 824
R2 / R2 adjusted 0.055 / 0.046 0.078 / 0.065

Explanation model2

The model has improved: The multiple R-squared is 0.078, indicating that approximately 7.8% of the variance in the dependent variable is explained by the predictors used. The adjusted R-squared is 0.065. Significant coefficients: If the respondent has a middle level of education, then the indicator of justification sex before the marriage increases by 0.30 If the respondent has never used the Internet, the indicator of justification sex before the marriage decreases by 0.40 If the respondent rarely used the Internet, the indicator of justification sex before the marriage decreases by -0.26

Also, Age and Index of postmaterialism became statistically significant after squaring.

In the model the interaction effect between age (Zage) and gender (gndr) on the dependent variable Zsex_bef_mar. The coefficient of -0.18 suggests that for females, for each one-unit increase in age, the predicted value of Zsex_bef_mar decreases by approximately 0.18 units on average. The p-value of 0.010 suggests that this interaction effect is statistically significant, indicating that the relationship between age and Zsex_bef_mar significantly differs between genders. Specifically, the negative coefficient suggests that as females get older, their attitude towards premarital sex tends to decrease more compared to males.

The F-statistic is 6.223, and the p-value is 6.748e-10, indicating the overall statistical significance of the model.

Model3

db <- db %>% 
  mutate(log_age = log(age),
         log_sex_bef_mar = log(sex_bef_mar))

db$log_ind_mat <- log(db$ind_mat + 0.0001)  # Добавляем небольшое смещение, чтобы избежать нулей

model3 <- lm(log_sex_bef_mar ~ educ_lvl + int_use + log_ind_mat + scale(log_age) * gndr, data = db)

summary(model3)
## 
## Call:
## lm(formula = log_sex_bef_mar ~ educ_lvl + int_use + log_ind_mat + 
##     scale(log_age) * gndr, data = db)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.7840 -0.5690  0.2708  0.6273  1.1361 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                1.39129    0.08919  15.600  < 2e-16 ***
## educ_lvlmiddle             0.23475    0.08948   2.624  0.00886 ** 
## educ_lvlhigher            -0.08589    0.09265  -0.927  0.35416    
## int_usenever              -0.15769    0.09057  -1.741  0.08206 .  
## int_userarely             -0.13925    0.07552  -1.844  0.06557 .  
## log_ind_mat                0.01259    0.01059   1.189  0.23484    
## scale(log_age)             0.07250    0.04592   1.579  0.11476    
## gndrfemale                 0.06915    0.05717   1.210  0.22675    
## scale(log_age):gndrfemale -0.15162    0.05772  -2.627  0.00878 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8163 on 815 degrees of freedom
## Multiple R-squared:  0.04202,    Adjusted R-squared:  0.03262 
## F-statistic: 4.469 on 8 and 815 DF,  p-value: 2.546e-05
sjPlot::tab_model(model3)
  justification of sexual
relationship before
marriage
Predictors Estimates CI p
(Intercept) 1.39 1.22 – 1.57 <0.001
highest educational
level: middle
0.23 0.06 – 0.41 0.009
highest educational
level: higher
-0.09 -0.27 – 0.10 0.354
int_usenever -0.16 -0.34 – 0.02 0.082
int_userarely -0.14 -0.29 – 0.01 0.066
index of postmaterialism 0.01 -0.01 – 0.03 0.235
scale(log_age) 0.07 -0.02 – 0.16 0.115
gender: female 0.07 -0.04 – 0.18 0.227
scale(log_age):gndrfemale -0.15 -0.26 – -0.04 0.009
Observations 824
R2 / R2 adjusted 0.042 / 0.033

The model has deteriorated, so I will not consider it further.

Linear Regression Assumptions model2

par(mfrow = c(2, 2))
plot(model2)

Linearity assumption: The Residuals vs. Fitted plot shows a horizontal line without distinct patterns, indicating that our data exhibits linearity.

The Q-Q plot displays deviations of residuals on both sides of the straight line (i.e., residual points are not evenly distributed on both sides of the line), which may indicate non-normal distribution of residuals.

The Scale-Location and Residuals vs. Leverage plots show a red horizontal line with equally spread points, indicating homoscedasticity of our data.

On the Residuals vs. Leverage plot, I can observe only a couple of outliers.

Checking for Multicollinearity.

vif(model2, type = 'predictor')
## GVIFs computed for predictors
##                     GVIF Df GVIF^(1/(2*Df)) Interacts With
## educ_lvl        1.705226  2        1.142735           --  
## int_use         1.978579  2        1.186010           --  
## Zind_mat        1.048154  1        1.023794           --  
## Zage            1.952611  3        1.117985           gndr
## gndr            1.952611  3        1.117985           Zage
## Zage_sq         1.220723  1        1.104863           --  
## Zsex_bef_mar_sq 1.028098  1        1.013951           --  
## Zind_mat_sq     1.010410  1        1.005192           --  
##                                                                      Other Predictors
## educ_lvl         int_use, Zind_mat, Zage, gndr, Zage_sq, Zsex_bef_mar_sq, Zind_mat_sq
## int_use         educ_lvl, Zind_mat, Zage, gndr, Zage_sq, Zsex_bef_mar_sq, Zind_mat_sq
## Zind_mat         educ_lvl, int_use, Zage, gndr, Zage_sq, Zsex_bef_mar_sq, Zind_mat_sq
## Zage               educ_lvl, int_use, Zind_mat, Zage_sq, Zsex_bef_mar_sq, Zind_mat_sq
## gndr               educ_lvl, int_use, Zind_mat, Zage_sq, Zsex_bef_mar_sq, Zind_mat_sq
## Zage_sq         educ_lvl, int_use, Zind_mat, Zage, gndr, Zsex_bef_mar_sq, Zind_mat_sq
## Zsex_bef_mar_sq         educ_lvl, int_use, Zind_mat, Zage, gndr, Zage_sq, Zind_mat_sq
## Zind_mat_sq         educ_lvl, int_use, Zind_mat, Zage, gndr, Zage_sq, Zsex_bef_mar_sq

Multicollinearity is missing

Interaction Plot

plot_model(model2, type = "int", terms = "Zage", mdrt.values = "quart")

## Explanation intereaction plot

My explanation of the interaction in the models was confirmed by the graph, indicating that as women age, their attitude towards premarital sex tends to decrease more compared to men. It’s also important to note that the lines intersected, suggesting that the influence of age on the approval of premarital sex is more pronounced among women at a younger age, whereas in men, this effect is more pronounced at an older age.