przeliczone wszystkie dane
This commit is contained in:
+65
-1
@@ -1,5 +1,6 @@
|
||||
# Przygotowanie danych do analiz projektu moralnosci
|
||||
#
|
||||
library(dplyr)
|
||||
# Skrypt:
|
||||
# 1. czyta surowe dane ankietowe,
|
||||
# 2. czyta wyniki eksperymentu karcianego,
|
||||
@@ -267,8 +268,71 @@ merged <- merge(
|
||||
|
||||
matched <- merged[!is.na(merged$exp_n_stacji), , drop = FALSE]
|
||||
|
||||
# liczenie fundamentów z gry
|
||||
|
||||
library(tidyverse)
|
||||
|
||||
# klucz stacji z pliku markdown
|
||||
klucz_stacji <- readr::read_tsv("stacje.md", show_col_types = FALSE) |>
|
||||
setNames(c("stacja", "fundament_a", "fundament_b")) |>
|
||||
mutate(
|
||||
negatywna = str_detect(stacja, "-"),
|
||||
stacja = as.integer(str_remove(stacja, "-"))
|
||||
)
|
||||
|
||||
|
||||
score_ipsatywne_fundamenty <- function(dane,
|
||||
klucz = klucz_stacji,
|
||||
id_col = "kod_uczestnika_clean",
|
||||
negative_weight = 1) {
|
||||
fundamenty <- c("Troska", "Sprawiedliwość", "Lojalność", "Autorytet")
|
||||
|
||||
long <- dane |>
|
||||
dplyr::select(dplyr::all_of(id_col), dplyr::matches("^wybor_final_stacja_\\d+$")) |>
|
||||
tidyr::pivot_longer(
|
||||
cols = dplyr::matches("^wybor_final_stacja_\\d+$"),
|
||||
names_to = "stacja_col",
|
||||
values_to = "wybor"
|
||||
) |>
|
||||
dplyr::mutate(
|
||||
id = .data[[id_col]],
|
||||
stacja = as.integer(stringr::str_extract(stacja_col, "\\d+")),
|
||||
wybor = stringr::str_to_lower(as.character(wybor))
|
||||
) |>
|
||||
dplyr::left_join(klucz, by = "stacja") |>
|
||||
dplyr::filter(wybor %in% c("a", "b")) |>
|
||||
dplyr::mutate(
|
||||
winner = dplyr::case_when(
|
||||
wybor == "a" & !negatywna ~ fundament_a,
|
||||
wybor == "b" & !negatywna ~ fundament_b,
|
||||
wybor == "a" & negatywna ~ fundament_b,
|
||||
wybor == "b" & negatywna ~ fundament_a
|
||||
),
|
||||
punkty = dplyr::if_else(negatywna, negative_weight, 1)
|
||||
)
|
||||
|
||||
wyniki_raw <- long |>
|
||||
dplyr::group_by(id, winner) |>
|
||||
dplyr::summarise(punkty = sum(punkty), .groups = "drop") |>
|
||||
tidyr::pivot_wider(
|
||||
names_from = winner,
|
||||
values_from = punkty,
|
||||
values_fill = 0
|
||||
) |> dplyr::arrange(id)
|
||||
|
||||
wyniki_raw
|
||||
}
|
||||
|
||||
|
||||
|
||||
profil_fundamentow <- score_ipsatywne_fundamenty(matched, negative_weight = 0.5) |>
|
||||
left_join(matched, by = c("id" = "kod_uczestnika_clean"))
|
||||
|
||||
|
||||
|
||||
# zapis
|
||||
write.csv2(merged, path("outputs", "dane_polaczone_skale.csv"), row.names = FALSE, na = "")
|
||||
write.csv2(matched, path("outputs", "dane_polaczone_skale_tylko_eksperyment.csv"), row.names = FALSE, na = "")
|
||||
write.csv2(profil_fundamentow, path("outputs", "dane_polaczone_skale_tylko_eksperyment.csv"), row.names = FALSE, na = "")
|
||||
write.csv2(experiment_long, path("outputs", "wyniki_eksperymentu_long.csv"), row.names = FALSE, na = "")
|
||||
write.csv2(experiment_prepared, path("outputs", "wyniki_eksperymentu_podsumowanie.csv"), row.names = FALSE, na = "")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user