Проанализируйте различия в оценках уверенности в нахождении заработка в случае потери актуального места работы (вопрос В21) в зависимости от образовательного уровня респондента (вопрос А6), перекодировав его в две категории - те, кто имеют высшее образование, и кто его не имеет.

library(haven)
База_КлимРиск_2023_ОБЩАЯ_от_31_10_23_с_правильными_типами_для_отчета <- read_sav("База_КлимРиск_2023_ОБЩАЯ от 31.10.23_с правильными типами для отчета.sav")
df<-База_КлимРиск_2023_ОБЩАЯ_от_31_10_23_с_правильными_типами_для_отчета
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(distributions3)
## 
## Attaching package: 'distributions3'
## The following object is masked from 'package:stats':
## 
##     Gamma
## The following object is masked from 'package:grDevices':
## 
##     pdf
library(BSDA)
## Loading required package: lattice
## 
## Attaching package: 'BSDA'
## The following object is masked from 'package:datasets':
## 
##     Orange
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.5.0     ✔ stringr   1.5.1
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
df<-df %>%
  mutate (V6_edu = case_when(
    V6<3 ~ "не высшее",
    V6>4 ~ "высшее")
  )

выбираем критерий Манна-Уитни, так как одна переменная категориальная (2 градации), а вторая порядковая.

wilcox.test(V21~V6_edu, data = df)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  V21 by V6_edu
## W = 354, p-value = 0.3068
## alternative hypothesis: true location shift is not equal to 0
library(gtsummary)
table<-df %>% 
  select(V21, V6_edu)  

наблюдаем, что люди с всшим образованием владеют большей уверенность в том, что смогут найти другую работу в случае потери основного заработка

table %>% 
  tbl_summary(missing="no")
## ℹ Column(s) V21 are class "haven_labelled". This is an intermediate datastructure not meant for analysis. Convert columns with `haven::as_factor()`, `labelled::to_factor()`, `labelled::unlabelled()`, and `unclass()`. "haven_labelled" value labels are ignored when columns are not converted. Failure to convert may have unintended consequences or result in error.
## • https://haven.tidyverse.org/articles/semantics.html
## • https://larmarange.github.io/labelled/articles/intro_labelled.html#unlabelled
Characteristic N = 9131
Если Вы потеряете основной вид заработка, насколько Вы уверены в том, что сможете найти другую работу, заработок?
    1 156 (28%)
    2 166 (29%)
    3 123 (22%)
    4 122 (22%)
V6_edu
    высшее 11 (4.9%)
    не высшее 214 (95%)
1 n (%)
table %>% 
  tbl_summary(by=V6_edu, missing="no") %>%
  modify_header(
    update = list(
      label ~ "" 
    )
  )
## 688 observations missing `V6_edu` have been removed. To include these observations, use `forcats::fct_na_value_to_level()` on `V6_edu` column before passing to `tbl_summary()`.
## ℹ Column(s) V21 are class "haven_labelled". This is an intermediate datastructure not meant for analysis. Convert columns with `haven::as_factor()`, `labelled::to_factor()`, `labelled::unlabelled()`, and `unclass()`. "haven_labelled" value labels are ignored when columns are not converted. Failure to convert may have unintended consequences or result in error.
## • https://haven.tidyverse.org/articles/semantics.html
## • https://larmarange.github.io/labelled/articles/intro_labelled.html#unlabelled
высшее, N = 111 не высшее, N = 2141
Если Вы потеряете основной вид заработка, насколько Вы уверены в том, что сможете найти другую работу, заработок?

    1 2 (25%) 27 (24%)
    2 5 (63%) 36 (32%)
    3 0 (0%) 29 (26%)
    4 1 (13%) 20 (18%)
1 n (%)

Используя созданную переменную важности соблюдения традиций (V18_3), проведите анализ по уровню образования (по переменной, созданной в упр.1) и по самооценке материального положения (вопрос А10), создав три категории - «низкие доходы», «средние доходы» и «высокие доходы, обеспеченные граждане». Используйте параметрические методы там, где это уместно, и непараметрические там, где возможно применение только таких методов. Обязательно создайте визуализации к вашим результатам.

df<-df %>%
  mutate (V10_cat = case_when(
    V10<2 ~ "низкие доходы",
    V10==3 ~ "средние доходы",
    V10>4 ~ "высокие доходы")
  )
library(rstatix)
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
library(ggstatsplot)
## You can cite this package as:
##      Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
##      Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167
library(car)
## Loading required package: carData
## 
## Attaching package: 'carData'
## The following objects are masked from 'package:BSDA':
## 
##     Vocab, Wool
## 
## Attaching package: 'car'
## The following object is masked from 'package:purrr':
## 
##     some
## The following object is masked from 'package:dplyr':
## 
##     recode
df$V1<-sjlabelled::as_label(df$V6_edu)
prop.table(table(df$V18_3, df$V6_edu), margin = 2)
##    
##         высшее  не высшее
##   1 0.12500000 0.03061224
##   2 0.00000000 0.09693878
##   3 0.12500000 0.26530612
##   4 0.75000000 0.60714286
wilcox.test(V18_3~V6_edu, data = df)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  V18_3 by V6_edu
## W = 873, p-value = 0.5328
## alternative hypothesis: true location shift is not equal to 0
library(vcd)
## Loading required package: grid
## 
## Attaching package: 'vcd'
## The following object is masked from 'package:BSDA':
## 
##     Trucks
library(BSDA)
library(packager)
 options(OutDec= ",") 
#создадим базовую таблицу
M<- table(df$V18_3, df$V6_edu)
#подпишем оси
names(dimnames(M)) = c("tradition","Education")
#создадим таблицу с надписями
labs <- round(prop.table(M,margin=2)*100, 1)
#обычная мозаичная диаграмма
mosaic(M, pop = FALSE, shade = TRUE)
#добавим значения в ячейках
labeling_cells(text = labs, margin = 0)(M)

library(rstatix)
library(dplyr)
library(distributions3)
library(BSDA)
library(tidyverse)
library(rstatix)
library(ggstatsplot)
library(car)

V10_cat and V18_3

у меня ничего не получилось((

Провести анализ таблиц сопряженности по исследованию по климату (две таблицы на ваш выбор) с помощью критерия хи-квадрат. Создать мозаичную диаграмму и ассоциативный график.

df$V1<-sjlabelled::as_label(df$V1)
prop.table(table(df$V19, df$V1), margin = 2)
##    
##        высшее не высшее
##   1 0,7500000 0,4773869
##   2 0,2500000 0,5226131
library(dplyr)
chisq.test(df$V1, df$V19)
## Warning in chisq.test(df$V1, df$V19): Chi-squared approximation may be
## incorrect
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  df$V1 and df$V19
## X-squared = 1,3266, df = 1, p-value = 0,2494
library(vcd)
 options(OutDec= ",") 
#создадим базовую таблицу
M<- table(df$V19, df$V1)
#подпишем оси
names(dimnames(M)) = c("Опасны ли тающие ледники?","Пол")
#создадим таблицу с надписями
labs <- round(prop.table(M,margin=2)*100, 1)
#обычная мозаичная диаграмма
mosaic(M, pop = FALSE, shade = TRUE)
#добавим значения в ячейках
labeling_cells(text = labs, margin = 0)(M)

struct <- structable(~ V19 + V1, data = df)
assoc(struct, data = df, shade=T, labeling_args = list(set_varnames = c(V1 = "Пол", V19="Опасны ли тающие ледники?")))

chisq.test(df$V1, df$V23)
## Warning in chisq.test(df$V1, df$V23): Chi-squared approximation may be
## incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  df$V1 and df$V23
## X-squared = 2,2236, df = 3, p-value = 0,5273
library(vcd)
 options(OutDec= ",") 
#создадим базовую таблицу
M<- table(df$V23, df$V1)
#подпишем оси
names(dimnames(M)) = c("удовлетворенность жизнью","Пол")
#создадим таблицу с надписями
labs <- round(prop.table(M,margin=1)*100, 1)
#обычная мозаичная диаграмма
mosaic(M, pop = FALSE, shade = TRUE)
#добавим значения в ячейках
labeling_cells(text = labs, margin = 0)(M)

struct <- structable(~ V23 + V1, data = df)
assoc(struct, data = df, shade=T, labeling_args = list(set_varnames = c(V1 = "Пол", V23="удовлетворенность жизнью")))

chisq.test(df$V1, df$V18_3)
## Warning in chisq.test(df$V1, df$V18_3): Chi-squared approximation may be
## incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  df$V1 and df$V18_3
## X-squared = 3,6095, df = 3, p-value = 0,3068
library(vcd)
 options(OutDec= ",") 
#создадим базовую таблицу
M<- table(df$V18_3, df$V1)
#подпишем оси
names(dimnames(M)) = c("важность традиций","Пол")
#создадим таблицу с надписями
labs <- round(prop.table(M,margin=2)*100, 1)
#обычная мозаичная диаграмма
mosaic(M, pop = FALSE, shade = TRUE)
#добавим значения в ячейках
labeling_cells(text = labs, margin = 0)(M)

struct <- structable(~ V18_3 + V1, data = df)
assoc(struct, data = df, shade=T, labeling_args = list(set_varnames = c(V1 = "Пол", V18_3="важность традиций")))

В рабочей консоли в таблица отображается пол как мужской и женщиский, при сшивании в описании пишет про образование. Не пойму в чем проблема(