1 Packages

pacman::p_load(readxl, tidyverse, janitor, arsenal, stringi, summarytools, correlation, emmeans, broom)

2 Data

temp = tempfile(fileext = ".xlsx")
dataURL <- "https://osf.io/download/gqdwm/"
download.file(dataURL, destfile=temp, mode='wb')

df <- readxl::read_excel("C:/Users/luisf/Dropbox/Puc-Rio/Projeto - Luciana Pessoa/kit instrumentos - O exercício da paternalidade em diferentes configurações familiares.xlsx", 
    col_types = c("numeric", "date", "text", 
        "text", "text", "text", "text", "text", 
        "text", "text", "text", "text", "text", 
        "numeric", "numeric", "text", "text", 
        "text", "text", "text", "text", "text", 
        "text", "text", "text", "numeric", 
        "text", "text", "text", "text", "text", 
        "text", "text", "text", "text", "text", 
        "numeric", "numeric", "numeric", 
        "numeric", "numeric", "numeric", 
        "numeric", "numeric", "numeric", 
        "numeric", "numeric", "numeric", 
        "numeric", "text", "text", "text", 
        "text", "text", "text", "numeric", 
        "text", "text", "text", "numeric", 
        "numeric", "numeric", "numeric", 
        "numeric"))
## Warning: Expecting numeric in N2 / R2C14: got a date
## Warning: Expecting numeric in Z2 / R2C26: got a date
## Warning: Expecting numeric in BD2 / R2C56: got a date
## Warning: Expecting numeric in N3 / R3C14: got a date
## Warning: Expecting numeric in Z3 / R3C26: got a date
## Warning: Expecting numeric in BD3 / R3C56: got a date
## Warning: Expecting numeric in N4 / R4C14: got a date
## Warning: Expecting numeric in Z4 / R4C26: got a date
## Warning: Expecting numeric in BD4 / R4C56: got a date
## Warning: Expecting numeric in N5 / R5C14: got a date
## Warning: Expecting numeric in Z5 / R5C26: got a date
## Warning: Expecting numeric in BD5 / R5C56: got a date
## Warning: Expecting numeric in N6 / R6C14: got a date
## Warning: Expecting numeric in Z6 / R6C26: got a date
## Warning: Expecting numeric in BD6 / R6C56: got a date
## Warning: Expecting numeric in N7 / R7C14: got a date
## Warning: Expecting numeric in Z7 / R7C26: got a date
## Warning: Expecting numeric in BD7 / R7C56: got a date
## Warning: Expecting numeric in N8 / R8C14: got a date
## Warning: Expecting numeric in Z8 / R8C26: got a date
## Warning: Expecting numeric in BD8 / R8C56: got a date
## Warning: Expecting numeric in N9 / R9C14: got a date
## Warning: Expecting numeric in Z9 / R9C26: got a date
## Warning: Expecting numeric in BD9 / R9C56: got a date
## Warning: Expecting numeric in N10 / R10C14: got a date
## Warning: Expecting numeric in Z10 / R10C26: got a date
## Warning: Expecting numeric in BD10 / R10C56: got a date
## Warning: Expecting numeric in N11 / R11C14: got a date
## Warning: Expecting numeric in Z11 / R11C26: got a date
## Warning: Expecting numeric in BD11 / R11C56: got a date
## Warning: Expecting numeric in N12 / R12C14: got a date
## Warning: Expecting numeric in Z12 / R12C26: got a date
## Warning: Expecting numeric in BD12 / R12C56: got a date
## Warning: Expecting numeric in N13 / R13C14: got a date
## Warning: Expecting numeric in Z13 / R13C26: got a date
## Warning: Expecting numeric in BD13 / R13C56: got a date
## Warning: Expecting numeric in N14 / R14C14: got a date
## Warning: Expecting numeric in Z14 / R14C26: got a date
## Warning: Expecting numeric in BD14 / R14C56: got a date
## Warning: Expecting numeric in N15 / R15C14: got a date
## Warning: Expecting numeric in Z15 / R15C26: got a date
## Warning: Expecting numeric in BD15 / R15C56: got a date
## Warning: Expecting numeric in N16 / R16C14: got a date
## Warning: Expecting numeric in Z16 / R16C26: got a date
## Warning: Expecting numeric in BD16 / R16C56: got a date
## Warning: Expecting numeric in N17 / R17C14: got a date
## Warning: Expecting numeric in Z17 / R17C26: got a date
## Warning: Expecting numeric in BD17 / R17C56: got a date
## Warning: Expecting numeric in N18 / R18C14: got a date
## Warning: Expecting numeric in Z18 / R18C26: got a date
## Warning: Expecting numeric in BD18 / R18C56: got a date
## Warning: Expecting numeric in N19 / R19C14: got a date
## Warning: Expecting numeric in Z19 / R19C26: got a date
## Warning: Expecting numeric in BD19 / R19C56: got a date
## Warning: Expecting numeric in N20 / R20C14: got a date
## Warning: Expecting numeric in Z20 / R20C26: got a date
## Warning: Expecting numeric in BD20 / R20C56: got a date
## Warning: Expecting numeric in N21 / R21C14: got a date
## Warning: Expecting numeric in Z21 / R21C26: got a date
## Warning: Expecting numeric in BD21 / R21C56: got a date
## Warning: Expecting numeric in N22 / R22C14: got a date
## Warning: Expecting numeric in Z22 / R22C26: got a date
## Warning: Expecting numeric in BD22 / R22C56: got a date
## Warning: Expecting numeric in N23 / R23C14: got a date
## Warning: Expecting numeric in Z23 / R23C26: got a date
## Warning: Expecting numeric in BD23 / R23C56: got a date
## Warning: Expecting numeric in N24 / R24C14: got a date
## Warning: Expecting numeric in Z24 / R24C26: got a date
## Warning: Expecting numeric in BD24 / R24C56: got a date
## Warning: Expecting numeric in N25 / R25C14: got a date
## Warning: Expecting numeric in Z25 / R25C26: got a date
## Warning: Expecting numeric in BD25 / R25C56: got a date
## Warning: Expecting numeric in N26 / R26C14: got a date
## Warning: Expecting numeric in Z26 / R26C26: got a date
## Warning: Expecting numeric in BD26 / R26C56: got a date
## Warning: Expecting numeric in N27 / R27C14: got a date
## Warning: Expecting numeric in Z27 / R27C26: got a date
## Warning: Expecting numeric in BD27 / R27C56: got a date
## Warning: Expecting numeric in N28 / R28C14: got a date
## Warning: Expecting numeric in Z28 / R28C26: got a date
## Warning: Expecting numeric in BD28 / R28C56: got a date
## Warning: Expecting numeric in N29 / R29C14: got a date
## Warning: Expecting numeric in Z29 / R29C26: got a date
## Warning: Expecting numeric in BD29 / R29C56: got a date
## Warning: Expecting numeric in N30 / R30C14: got a date
## Warning: Expecting numeric in Z30 / R30C26: got a date
## Warning: Expecting numeric in BD30 / R30C56: got a date
## Warning: Expecting numeric in N31 / R31C14: got a date
## Warning: Expecting numeric in Z31 / R31C26: got a date
## Warning: Expecting numeric in BD31 / R31C56: got a date
## Warning: Expecting numeric in N32 / R32C14: got a date
## Warning: Expecting numeric in Z32 / R32C26: got a date
## Warning: Expecting numeric in BD32 / R32C56: got a date
## Warning: Expecting numeric in N33 / R33C14: got a date
## Warning: Expecting numeric in Z33 / R33C26: got a date
## Warning: Expecting numeric in BD33 / R33C56: got a date
## Warning: Expecting numeric in N34 / R34C14: got a date
## Warning: Expecting numeric in Z34 / R34C26: got a date
## Warning: Expecting numeric in BD34 / R34C56: got a date
## Warning: Expecting numeric in N35 / R35C14: got a date
## Warning: Expecting numeric in Z35 / R35C26: got a date
## Warning: Expecting numeric in BD35 / R35C56: got a date
## Warning: Expecting numeric in N36 / R36C14: got a date
## Warning: Expecting numeric in Z36 / R36C26: got a date
## Warning: Expecting numeric in BD36 / R36C56: got a date
## Warning: Expecting numeric in N37 / R37C14: got a date
## Warning: Expecting numeric in Z37 / R37C26: got a date
## Warning: Expecting numeric in BD37 / R37C56: got a date
## Warning: Expecting numeric in N38 / R38C14: got a date
## Warning: Expecting numeric in Z38 / R38C26: got a date
## Warning: Expecting numeric in BD38 / R38C56: got a date
## Warning: Expecting numeric in N39 / R39C14: got a date
## Warning: Expecting numeric in Z39 / R39C26: got a date
## Warning: Expecting numeric in BD39 / R39C56: got a date
## Warning: Expecting numeric in N40 / R40C14: got a date
## Warning: Expecting numeric in Z40 / R40C26: got a date
## Warning: Expecting numeric in BD40 / R40C56: got a date
## Warning: Expecting numeric in N41 / R41C14: got a date
## Warning: Expecting numeric in Z41 / R41C26: got a date
## Warning: Expecting numeric in BD41 / R41C56: got a date
## Warning: Expecting numeric in N42 / R42C14: got a date
## Warning: Expecting numeric in Z42 / R42C26: got a date
## Warning: Expecting numeric in BD42 / R42C56: got a date
## Warning: Expecting numeric in N43 / R43C14: got a date
## Warning: Expecting numeric in Z43 / R43C26: got a date
## Warning: Expecting numeric in BD43 / R43C56: got a date
## Warning: Expecting numeric in N44 / R44C14: got a date
## Warning: Expecting numeric in Z44 / R44C26: got a date
## Warning: Expecting numeric in BD44 / R44C56: got a date
## Warning: Expecting numeric in N45 / R45C14: got a date
## Warning: Expecting numeric in Z45 / R45C26: got a date
## Warning: Expecting numeric in BD45 / R45C56: got a date
## Warning: Expecting numeric in N46 / R46C14: got a date
## Warning: Expecting numeric in Z46 / R46C26: got a date
## Warning: Expecting numeric in BD46 / R46C56: got a date
## Warning: Expecting numeric in N47 / R47C14: got a date
## Warning: Expecting numeric in Z47 / R47C26: got a date
## Warning: Expecting numeric in BD47 / R47C56: got a date
## Warning: Expecting numeric in N48 / R48C14: got a date
## Warning: Expecting numeric in Z48 / R48C26: got a date
## Warning: Expecting numeric in BD48 / R48C56: got a date
## Warning: Expecting numeric in N49 / R49C14: got a date
## Warning: Expecting numeric in Z49 / R49C26: got a date
## Warning: Expecting numeric in BD49 / R49C56: got a date
## Warning: Expecting numeric in N50 / R50C14: got a date
## Warning: Expecting numeric in Z50 / R50C26: got a date
## Warning: Expecting numeric in BD50 / R50C56: got a date
## Warning: Expecting numeric in N51 / R51C14: got a date
## Warning: Expecting numeric in Z51 / R51C26: got a date
## Warning: Expecting numeric in BD51 / R51C56: got a date
## Warning: Expecting numeric in N52 / R52C14: got a date
## Warning: Expecting numeric in Z52 / R52C26: got a date
## Warning: Expecting numeric in BD52 / R52C56: got a date
## Warning: Expecting numeric in N53 / R53C14: got a date
## Warning: Expecting numeric in Z53 / R53C26: got a date
## Warning: Expecting numeric in BD53 / R53C56: got a date
## Warning: Expecting numeric in N54 / R54C14: got a date
## Warning: Expecting numeric in Z54 / R54C26: got a date
## Warning: Expecting numeric in BD54 / R54C56: got a date
## Warning: Expecting numeric in N55 / R55C14: got a date
## Warning: Expecting numeric in Z55 / R55C26: got a date
## Warning: Expecting numeric in BD55 / R55C56: got a date
## Warning: Expecting numeric in N56 / R56C14: got a date
## Warning: Expecting numeric in Z56 / R56C26: got a date
## Warning: Expecting numeric in BD56 / R56C56: got a date
## Warning: Expecting numeric in N57 / R57C14: got a date
## Warning: Expecting numeric in Z57 / R57C26: got a date
## Warning: Expecting numeric in BD57 / R57C56: got a date
## Warning: Expecting numeric in N58 / R58C14: got a date
## Warning: Expecting numeric in Z58 / R58C26: got a date
## Warning: Expecting numeric in BD58 / R58C56: got a date
## Warning: Expecting numeric in N59 / R59C14: got a date
## Warning: Expecting numeric in Z59 / R59C26: got a date
## Warning: Expecting numeric in BD59 / R59C56: got a date
## Warning: Expecting numeric in N60 / R60C14: got a date
## Warning: Expecting numeric in Z60 / R60C26: got a date
## Warning: Expecting numeric in BD60 / R60C56: got a date
## Warning: Expecting numeric in N61 / R61C14: got a date
## Warning: Expecting numeric in Z61 / R61C26: got a date
## Warning: Expecting numeric in BD61 / R61C56: got a date
## Warning: Expecting numeric in N62 / R62C14: got a date
## Warning: Expecting numeric in Z62 / R62C26: got a date
## Warning: Expecting numeric in BD62 / R62C56: got a date
## Warning: Expecting numeric in N63 / R63C14: got a date
## Warning: Expecting numeric in Z63 / R63C26: got a date
## Warning: Expecting numeric in BD63 / R63C56: got a date
## Warning: Expecting numeric in N64 / R64C14: got a date
## Warning: Expecting numeric in Z64 / R64C26: got a date
## Warning: Expecting numeric in BD64 / R64C56: got a date
## Warning: Expecting numeric in N65 / R65C14: got a date
## Warning: Expecting numeric in Z65 / R65C26: got a date
## Warning: Expecting numeric in BD65 / R65C56: got a date
## Warning: Expecting numeric in N66 / R66C14: got a date
## Warning: Expecting numeric in Z66 / R66C26: got a date
## Warning: Expecting numeric in BD66 / R66C56: got a date
## Warning: Expecting numeric in N67 / R67C14: got a date
## Warning: Expecting numeric in Z67 / R67C26: got a date
## Warning: Expecting numeric in BD67 / R67C56: got a date
## Warning: Expecting numeric in N68 / R68C14: got a date
## Warning: Expecting numeric in Z68 / R68C26: got a date
## Warning: Expecting numeric in BD68 / R68C56: got a date
## Warning: Expecting numeric in N69 / R69C14: got a date
## Warning: Expecting numeric in Z69 / R69C26: got a date
## Warning: Expecting numeric in BD69 / R69C56: got a date
## Warning: Expecting numeric in N70 / R70C14: got a date
## Warning: Expecting numeric in Z70 / R70C26: got a date
## Warning: Expecting numeric in BD70 / R70C56: got a date
## Warning: Expecting numeric in N71 / R71C14: got a date
## Warning: Expecting numeric in Z71 / R71C26: got a date
## Warning: Expecting numeric in BD71 / R71C56: got a date
## Warning: Expecting numeric in N72 / R72C14: got a date
## Warning: Expecting numeric in Z72 / R72C26: got a date
## Warning: Expecting numeric in BD72 / R72C56: got a date
## Warning: Expecting numeric in N73 / R73C14: got a date
## Warning: Expecting numeric in Z73 / R73C26: got a date
## Warning: Expecting numeric in BD73 / R73C56: got a date
## Warning: Expecting numeric in N74 / R74C14: got a date
## Warning: Expecting numeric in Z74 / R74C26: got a date
## Warning: Expecting numeric in BD74 / R74C56: got a date
## Warning: Expecting numeric in N75 / R75C14: got a date
## Warning: Expecting numeric in Z75 / R75C26: got a date
## Warning: Expecting numeric in BD75 / R75C56: got a date
## Warning: Expecting numeric in N76 / R76C14: got a date
## Warning: Expecting numeric in Z76 / R76C26: got a date
## Warning: Expecting numeric in BD76 / R76C56: got a date
## Warning: Expecting numeric in N77 / R77C14: got a date
## Warning: Expecting numeric in Z77 / R77C26: got a date
## Warning: Expecting numeric in BD77 / R77C56: got a date
## Warning: Expecting numeric in N78 / R78C14: got a date
## Warning: Expecting numeric in Z78 / R78C26: got a date
## Warning: Expecting numeric in BD78 / R78C56: got a date
## Warning: Expecting numeric in N79 / R79C14: got a date
## Warning: Expecting numeric in Z79 / R79C26: got a date
## Warning: Expecting numeric in BD79 / R79C56: got a date
## Warning: Expecting numeric in N80 / R80C14: got a date
## Warning: Expecting numeric in Z80 / R80C26: got a date
## Warning: Expecting numeric in BD80 / R80C56: got a date
## Warning: Expecting numeric in N81 / R81C14: got a date
## Warning: Expecting numeric in Z81 / R81C26: got a date
## Warning: Expecting numeric in BD81 / R81C56: got a date
## Warning: Expecting numeric in N82 / R82C14: got a date
## Warning: Expecting numeric in Z82 / R82C26: got a date
## Warning: Expecting numeric in BD82 / R82C56: got a date
## Warning: Expecting numeric in N83 / R83C14: got a date
## Warning: Expecting numeric in Z83 / R83C26: got a date
## Warning: Expecting numeric in BD83 / R83C56: got a date
## New names:
## • `` -> `...1`
## • `Por quê?` -> `Por quê?...52`
## • `Por quê?` -> `Por quê?...55`
## • `` -> `...60`
## • `` -> `...61`
## • `` -> `...62`
## • `` -> `...63`
## • `` -> `...64`
backup = df
df

3 Clean

df = clean_names(df)
df = remove_empty(df)
## value for "which" not specified, defaulting to c("rows", "cols")
df <- df %>% 
  mutate(across(where(is.character), ~ tolower(.) %>% stri_trans_general("Latin-ASCII")))
df

4 Summary

#view(dfSummary(df))

4.1 completed

df = df %>% mutate(
  valid = case_when(
    se_esta_completo == "\r\nfalta complementar" ~ "not completed",
    se_esta_completo == "falta complementar" ~ "not completed",
    se_esta_completo == "falta completar" ~ "fnot completed",
    se_esta_completo == "preencheu duas vezes" ~ "filled out several times",
    se_esta_completo == "preencheu mais vezes" ~ "filled out several times",
    se_esta_completo == "invalido" ~ "invalid",
    se_esta_completo == "completo" ~ "complete",
    
    TRUE ~ NA_character_
  )) 
df %>% count(valid)

4.2 Parents information

df =  df %>% 
  mutate(age_parent = as.numeric(idade_referente_a_quem_esta_preenchendo),
         place_born = naturalidade_referente_a_quem_esta_preenchendo,
         how_many_children = as.numeric(numero_de_filhos_referente_a_quem_esta_preenchendo),
         how_many_people_at_home = as.numeric(numero_de_pessoas_que_residem_na_casa_referente_a_quem_esta_preenchendo),
         marital_status = estado_civil_referente_a_quem_esta_preenchendo
  ) %>%
  mutate(education = as.factor(case_when(
    escolaridade_referente_a_quem_esta_preenchendo == "ensino fundamental incompleto" ~ "1 elementary",
    escolaridade_referente_a_quem_esta_preenchendo == "ensino fundamental completo" ~ "1 elementary",
    escolaridade_referente_a_quem_esta_preenchendo == "ensino medio incompleto" ~ "2 high school",
    escolaridade_referente_a_quem_esta_preenchendo == "ensino medio completo" ~ "2 high school",
    escolaridade_referente_a_quem_esta_preenchendo == "superior incompleto" ~ "3 undergraduate",
    escolaridade_referente_a_quem_esta_preenchendo == "superior completo" ~ "3 undergraduate",
    escolaridade_referente_a_quem_esta_preenchendo == "pos-graduacao" ~ "4 graduate",
    TRUE ~ NA_character_
  ))) 


df = df %>%
  rename(parents_name = nome_do_respondente)

df = df %>% rename(main = x1)
df = df %>% mutate(main =as.integer(stringr::str_extract(main, "\\d+")))


df = df %>%
  rename(complement = o_complementar)
df = df %>% mutate(complement =as.integer(stringr::str_extract(complement, "\\d+")))

df %>% 
  count(numero_de_filhos_referente_a_quem_esta_preenchendo)
df = df%>% 
  mutate(number_of_children = as.numeric(numero_de_filhos_referente_a_quem_esta_preenchendo) ) 

4.3 Family information

df = df %>% 
  mutate(family_type = 
           as.factor(tenho_pelo_menos_um_filho_a_de_ate_seis_anos_de_idade_e_minha_configuracao_familiar_se_enquadra_em))
df = df %>% rename(address = endereco)
df %>% count(family_type)
df = df %>% 
  mutate(family_type_cat = case_when(
    family_type  == "nuclear (pai e mae casados, sem filhos de casamentos anteriores)"   ~  "nuclear"   ,
    family_type  == "recasadas (pai e mae casados e pelo menos um deles com no minimo um filho(a) de casamentos anteriores)"     ~  "remarried",
    family_type  == "monoparental (mae sendo a unica responsavel pelo cuidado do filho)"     ~  "Monoparental"  ,
    family_type  == "homoafetiva (duas maes)"    ~  "homoaffective - mothers"   ,
    TRUE ~ NA_character_))
df %>% count(family_type, family_type_cat)
df %>% 
  count(numero_de_pessoas_que_residem_na_casa_referente_a_quem_esta_preenchendo)
df = df%>% 
  mutate(people_living_together = as.numeric(numero_de_pessoas_que_residem_na_casa_referente_a_quem_esta_preenchendo) ) 

4.4 child information

df = df %>% 
  mutate(child_age_months = case_when(
    idade_referente_a_crianca  ==   "01 ano e 10 meses"  ~  22  ,
    idade_referente_a_crianca  ==   "3"  ~  36  ,
    idade_referente_a_crianca  ==   "5"  ~  60  ,
    idade_referente_a_crianca  ==   "6"  ~  72  ,
    idade_referente_a_crianca  ==   "1"  ~  12  ,
    idade_referente_a_crianca  ==   "1 ano"  ~  12  ,
    idade_referente_a_crianca  ==   "1 ano e 11 meses"   ~  13  ,
    idade_referente_a_crianca  ==   "1 mes"  ~  1   ,
    idade_referente_a_crianca  ==   "10"     ~  120 ,
    idade_referente_a_crianca  ==   "10 meses"   ~  10  ,
    idade_referente_a_crianca  ==   "11"     ~  132 ,
    idade_referente_a_crianca  ==   "1ano9meses"     ~  21  ,
    idade_referente_a_crianca  ==   "2"  ~  24  ,
    idade_referente_a_crianca  ==   "2 anos"     ~  24  ,
    idade_referente_a_crianca  ==   "2 anos e 10 meses"  ~  34  ,
    idade_referente_a_crianca  ==   "2 anos e 4 meses"   ~  28  ,
    idade_referente_a_crianca  ==   "2 anos e meio"  ~  30  ,
    idade_referente_a_crianca  ==   "2 e 4"  ~  2   ,
    idade_referente_a_crianca  ==   "2a 6m"  ~  30  ,
    idade_referente_a_crianca  ==   "2a6m"   ~  30  ,
    idade_referente_a_crianca  ==   "3"  ~  36  ,
    idade_referente_a_crianca  ==   "3 anos"     ~  36  ,
    idade_referente_a_crianca  ==   "3 meses"    ~  3   ,
    idade_referente_a_crianca  ==   "4"  ~  48  ,
    idade_referente_a_crianca  ==   "5"  ~  60  ,
    idade_referente_a_crianca  ==   "5 anos"     ~  60  ,
    idade_referente_a_crianca  ==   "5 meses"    ~  5   ,
    idade_referente_a_crianca  ==   "6"  ~  72  ,
    idade_referente_a_crianca  ==   "7"  ~  84,
    idade_referente_a_crianca  ==   "8"  ~  96  ,
    idade_referente_a_crianca  ==   "8 anos"     ~  96  ,
    idade_referente_a_crianca  ==   "8 meses"    ~  8,
    TRUE  ~ NA))


df = df %>%
  rename(childs_name = o_nome_do_filho_escolhido_por_ambos_os_responsaveis)

4.5 Scales

4.6 Socialization

df = df %>% 
  rename_at(vars(durante_os_primeiros_tres_anos_de_vida_as_criancas_deveriam_saber_controlar_emocoes:
                   durante_os_primeiros_tres_anos_de_vida_as_criancas_deveriam_desenvolver_um_senso_de_identidade),  ~paste0("socialization_goal_",1:10))


df = df %>% 
  mutate_at(vars(socialization_goal_1:
                   socialization_goal_10), 
            ~case_when(
              . == "nem um pouco" ~ 1, 
              . == "um pouco" ~ 2, 
              . == "mais ou menos" ~ 3, 
              . == "muito" ~ 4, 
              . == "completamente" ~ 5, 
            ))

4.6.1 Soc interdependency

df = df %>% 
  mutate(socialization_goal_interd = rowSums(select(.,socialization_goal_1,
                                                    socialization_goal_4,
                                                    socialization_goal_5,
                                                    socialization_goal_6,
                                                    socialization_goal_8), na.rm=T)) 

4.6.2 Soc autonomy

df = df %>% 
  mutate(socialization_goal_autonomy = rowSums(select(.,socialization_goal_2,
                                                    socialization_goal_3,
                                                    socialization_goal_7,
                                                    socialization_goal_9,
                                                    socialization_goal_10), na.rm=T)) 

4.6.3 Total score

df = df %>% 
  mutate(socialization_goal_total = rowSums(select(.,socialization_goal_1:
                   socialization_goal_10), na.rm=T)) 
df %>%
  select(socialization_goal_interd, socialization_goal_autonomy) %>%
  correlation()

4.6.4 Reliability

df %>% select(socialization_goal_1:
                   socialization_goal_10) %>%
  psych::alpha()
## 
## Reliability analysis   
## Call: psych::alpha(x = .)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean  sd median_r
##        0.9       0.9    0.92      0.47 8.8 0.016  2.7 0.8     0.48
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.86   0.9  0.93
## Duhachek  0.87   0.9  0.93
## 
##  Reliability if an item is dropped:
##                       raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r
## socialization_goal_1       0.90      0.90    0.92      0.50 9.1    0.016 0.016
## socialization_goal_2       0.89      0.88    0.91      0.46 7.7    0.017 0.025
## socialization_goal_3       0.89      0.89    0.91      0.47 8.0    0.017 0.022
## socialization_goal_4       0.88      0.88    0.90      0.44 7.2    0.018 0.021
## socialization_goal_5       0.88      0.88    0.90      0.45 7.4    0.018 0.019
## socialization_goal_6       0.88      0.88    0.91      0.45 7.4    0.018 0.020
## socialization_goal_7       0.89      0.89    0.91      0.46 7.7    0.018 0.022
## socialization_goal_8       0.88      0.88    0.91      0.45 7.5    0.018 0.022
## socialization_goal_9       0.90      0.90    0.92      0.49 8.7    0.016 0.021
## socialization_goal_10      0.90      0.90    0.92      0.49 8.6    0.016 0.021
##                       med.r
## socialization_goal_1   0.51
## socialization_goal_2   0.45
## socialization_goal_3   0.49
## socialization_goal_4   0.42
## socialization_goal_5   0.46
## socialization_goal_6   0.48
## socialization_goal_7   0.44
## socialization_goal_8   0.44
## socialization_goal_9   0.51
## socialization_goal_10  0.53
## 
##  Item statistics 
##                        n raw.r std.r r.cor r.drop mean   sd
## socialization_goal_1  82  0.52  0.55  0.49   0.44  2.0 0.84
## socialization_goal_2  82  0.75  0.76  0.72   0.69  2.8 0.96
## socialization_goal_3  82  0.71  0.71  0.68   0.63  3.1 1.11
## socialization_goal_4  82  0.83  0.84  0.84   0.78  3.0 1.08
## socialization_goal_5  82  0.81  0.80  0.80   0.75  3.0 1.21
## socialization_goal_6  82  0.81  0.80  0.80   0.75  2.8 1.23
## socialization_goal_7  82  0.76  0.75  0.72   0.68  3.0 1.22
## socialization_goal_8  82  0.80  0.79  0.78   0.73  2.5 1.22
## socialization_goal_9  82  0.59  0.60  0.55   0.50  1.9 0.99
## socialization_goal_10 82  0.63  0.62  0.56   0.53  3.0 1.12
## 
## Non missing response frequency for each item
##                          1    2    3    4    5 miss
## socialization_goal_1  0.30 0.49 0.15 0.06 0.00 0.06
## socialization_goal_2  0.09 0.28 0.41 0.18 0.04 0.06
## socialization_goal_3  0.05 0.32 0.28 0.23 0.12 0.06
## socialization_goal_4  0.07 0.28 0.35 0.20 0.10 0.06
## socialization_goal_5  0.11 0.29 0.26 0.22 0.12 0.06
## socialization_goal_6  0.15 0.32 0.21 0.23 0.10 0.06
## socialization_goal_7  0.11 0.26 0.23 0.28 0.12 0.06
## socialization_goal_8  0.23 0.29 0.24 0.16 0.07 0.06
## socialization_goal_9  0.48 0.23 0.24 0.04 0.01 0.06
## socialization_goal_10 0.10 0.23 0.30 0.28 0.09 0.06

4.7 Parental Values

df = df %>% 
  rename_at(vars(ter_boas_maneiras:
                   esforcar_se_para_ter_sucesso),  ~paste0("values_",1:13))
df = df %>% 
  mutate_at(vars(values_1:values_13), ~as.numeric(.))

4.7.1 Values conformity

2 [Ter interesse em como e por que as coisas acontecem] 8 [Ser um bom/boa aluno (a)] 10 [Ter bom senso e bom julgamento] 13 [Esforçar-se para ter sucesso]

df = df %>% 
  mutate(values_conformity = rowSums(select(.,values_2,values_8, values_10, values_13)))

4.7.2 Values Self-direction

1 [Ter boas maneiras] 3 [Ser responsável] 7 [Ter auto-controle] 9 [Obedecer aos pais] 12 [Ser honesto (a)]

df = df %>% 
  mutate(values_self_direction = rowSums(select(.,values_1,values_3,values_7,values_9,values_12)))

4.7.3 Values filler

4 [Ter consideração pelos outros] 5 [Ser arrumado (a) e limpo (a)] 6 [Agir como um menino (a) deveria agir] 11 [Ter um bom relacionamento com as outras crianças]

df = df %>% 
  mutate(values_filler = rowSums(select(.,values_4,values_5,values_6,values_11)))

4.7.4 Total Score

df %>% 
  summarise_at(vars(values_1:values_13), mean, na.rm=T) %>% 
  mutate(values_total = rowSums(select(.,values_1:
                   values_13), na.rm=T)) 
df = df %>% 
  mutate(values_total = rowSums(select(.,values_1:values_13), na.rm=T)) 

4.8 Export dataframe

#write.csv(df, "df_luciana_family.csv", row.names = F)

5 DA

5.1 Table one

df %>% 
  select(child_age_months, age_parent, education, people_living_together,number_of_children,family_type_cat, marital_status) %>%
  tableby( ~ ., data = .) %>%
  summary(text = T, digits = 2) %>%
  as.data.frame()

5.2 Distribution of the results

df %>%
  select(socialization_goal_total, values_total) %>%
  rename("Metas de socialização/desenvolvimento" = socialization_goal_total,
         "Valores parentais" = values_total) %>%
  as.data.frame() %>%
  pivot_longer(everything()) %>%
  ggplot(., aes(x = value, fill = name)) + geom_density(alpha=0.3) +
  #scale_x_continuous(breaks=seq(-3,3,1), limits=c(-4,3))+
  labs(x = "Resultado", y = "Densidade", fill = "") + 
  theme_bw() + theme(legend.position = "bottom") + 
  facet_wrap(  ~ name)

## Group comparison

df %>%
  select(family_type, values_total) %>%
  #rename( "Configuração Familiar" = tipo_familia_cat,
  #        "Estilo parental" = estilo_parental_total,
  #       "Valores parentais" = valores_total) %>%
  pivot_longer(-family_type) %>%
  ggplot(., aes(x = family_type, y = value, fill = family_type)) +
  geom_bar(stat = "summary", position = "dodge") +
   stat_summary(fun.data="mean_se",geom="errorbar",
                width=0.5,
                position=position_dodge(width=0.9)) +
  theme_bw() + labs(fill = "Configuração familiar",  x = "Configuração familiar", y = "Resultado médio") +
  theme(legend.position = "hide") +
   theme(panel.border = element_blank(),
        axis.text.x = element_text(angle = 60, vjust = 1, hjust = 1)) +
  scale_x_discrete(labels = function(x) str_wrap(str_replace_all(x, "foo" , " "),
                                                 width = 40))
## No summary function supplied, defaulting to `mean_se()`

df %>%
  select(family_type_cat, 
         socialization_goal_interd, socialization_goal_autonomy, socialization_goal_total, 
         values_conformity,values_self_direction,values_filler,values_total) %>%
   tableby(family_type_cat ~ ., data = .) %>%
  summary(text = T, digits = 2) %>%
  as.data.frame()

5.2.1 Get means

df %>%
  select(family_type_cat, values_1:values_13) %>%
  group_by(family_type_cat) %>%
  summarise_all(mean, na.rm=T) %>% 
  t %>% as.data.frame() %>%
   rownames_to_column() %>% 
  `colnames<-`(.[1,]) %>%
  slice(-1)

5.2.2 Get sds

df %>%
  select(family_type_cat, values_1:values_13) %>%
  group_by(family_type_cat) %>%
  summarise_all(sd, na.rm=T) %>% 
  t %>% as.data.frame() %>%
   rownames_to_column() %>% 
  `colnames<-`(.[1,]) %>%
  slice(-1)

5.3 Exploratory ANOVA

5.3.1 Values general

df %>%
 select(family_type_cat, values_1:values_13) %>%
  pivot_longer(-family_type_cat) %>%
  group_by(name) %>%
  nest() %>% 
  mutate(
    aov_results = map(data, ~aov(value ~ family_type_cat, data = .)),
    tidied = map(aov_results, tidy)
  ) %>%
  unnest(tidied) %>% 
  filter(!is.na(p.value)) %>% # %>% arrange(p.value)
  mutate_if(is.numeric, round,3)
## `mutate_if()` ignored the following grouping variables:
## • Column `name`

5.3.2 Value 4

emmeans(lm(df$values_4 ~ df$family_type_cat), pairwise ~ family_type_cat, adjust = "tukey")
## $emmeans
##  family_type_cat         emmean    SE df lower.CL upper.CL
##  homoaffective - mothers   4.17 0.332 78     3.51     4.83
##  Monoparental              3.89 0.192 78     3.51     4.27
##  nuclear                   4.55 0.129 78     4.29     4.81
##  remarried                 4.22 0.192 78     3.84     4.60
## 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast                                 estimate    SE df t.ratio p.value
##  (homoaffective - mothers) - Monoparental   0.2778 0.383 78   0.724  0.8871
##  (homoaffective - mothers) - nuclear       -0.3833 0.356 78  -1.076  0.7049
##  (homoaffective - mothers) - remarried     -0.0556 0.383 78  -0.145  0.9989
##  Monoparental - nuclear                    -0.6611 0.231 78  -2.863  0.0271
##  Monoparental - remarried                  -0.3333 0.271 78  -1.229  0.6103
##  nuclear - remarried                        0.3278 0.231 78   1.420  0.4911
## 
## P value adjustment: tukey method for comparing a family of 4 estimates
emmeans(lm(df$values_4 ~ df$family_type_cat), pairwise ~ family_type_cat, adjust = "bonferroni")
## $emmeans
##  family_type_cat         emmean    SE df lower.CL upper.CL
##  homoaffective - mothers   4.17 0.332 78     3.51     4.83
##  Monoparental              3.89 0.192 78     3.51     4.27
##  nuclear                   4.55 0.129 78     4.29     4.81
##  remarried                 4.22 0.192 78     3.84     4.60
## 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast                                 estimate    SE df t.ratio p.value
##  (homoaffective - mothers) - Monoparental   0.2778 0.383 78   0.724  1.0000
##  (homoaffective - mothers) - nuclear       -0.3833 0.356 78  -1.076  1.0000
##  (homoaffective - mothers) - remarried     -0.0556 0.383 78  -0.145  1.0000
##  Monoparental - nuclear                    -0.6611 0.231 78  -2.863  0.0323
##  Monoparental - remarried                  -0.3333 0.271 78  -1.229  1.0000
##  nuclear - remarried                        0.3278 0.231 78   1.420  0.9583
## 
## P value adjustment: bonferroni method for 6 tests
emmeans(lm(df$values_8 ~ df$family_type_cat), pairwise ~ family_type_cat, adjust = "tukey")
## $emmeans
##  family_type_cat         emmean    SE df lower.CL upper.CL
##  homoaffective - mothers   2.50 0.391 78     1.72     3.28
##  Monoparental              3.56 0.226 78     3.11     4.00
##  nuclear                   3.50 0.151 78     3.20     3.80
##  remarried                 3.72 0.226 78     3.27     4.17
## 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast                                 estimate    SE df t.ratio p.value
##  (homoaffective - mothers) - Monoparental  -1.0556 0.452 78  -2.338  0.0983
##  (homoaffective - mothers) - nuclear       -1.0000 0.419 78  -2.385  0.0885
##  (homoaffective - mothers) - remarried     -1.2222 0.452 78  -2.707  0.0407
##  Monoparental - nuclear                     0.0556 0.272 78   0.204  0.9970
##  Monoparental - remarried                  -0.1667 0.319 78  -0.522  0.9535
##  nuclear - remarried                       -0.2222 0.272 78  -0.817  0.8460
## 
## P value adjustment: tukey method for comparing a family of 4 estimates
emmeans(lm(df$values_8 ~ df$family_type_cat), pairwise ~ family_type_cat, adjust = "bonferroni")
## $emmeans
##  family_type_cat         emmean    SE df lower.CL upper.CL
##  homoaffective - mothers   2.50 0.391 78     1.72     3.28
##  Monoparental              3.56 0.226 78     3.11     4.00
##  nuclear                   3.50 0.151 78     3.20     3.80
##  remarried                 3.72 0.226 78     3.27     4.17
## 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast                                 estimate    SE df t.ratio p.value
##  (homoaffective - mothers) - Monoparental  -1.0556 0.452 78  -2.338  0.1318
##  (homoaffective - mothers) - nuclear       -1.0000 0.419 78  -2.385  0.1171
##  (homoaffective - mothers) - remarried     -1.2222 0.452 78  -2.707  0.0500
##  Monoparental - nuclear                     0.0556 0.272 78   0.204  1.0000
##  Monoparental - remarried                  -0.1667 0.319 78  -0.522  1.0000
##  nuclear - remarried                       -0.2222 0.272 78  -0.817  1.0000
## 
## P value adjustment: bonferroni method for 6 tests

5.3.3 Socialization goals

df %>%
 select(family_type_cat, socialization_goal_1:socialization_goal_10) %>%
  pivot_longer(-family_type_cat) %>%
  group_by(name) %>%
  nest()%>% 
  mutate(
    aov_results = map(data, ~aov(value ~ family_type_cat, data = .)),
    tidied = map(aov_results, tidy)
  ) %>%
  unnest(tidied) %>% 
  filter(!is.na(p.value))# %>% arrange(p.value)

5.3.4 Get means

df %>%
  select(family_type_cat, socialization_goal_1:socialization_goal_10) %>%
  group_by(family_type_cat) %>%
  summarise_all(mean, na.rm=T) %>% 
  t %>% as.data.frame() %>%
   rownames_to_column() %>% 
  `colnames<-`(.[1,]) %>%
  slice(-1)

5.3.5 Get sds

df %>%
  select(family_type_cat, socialization_goal_1:socialization_goal_10) %>%
  group_by(family_type_cat) %>%
  summarise_all(sd, na.rm=T) %>% 
  t %>% as.data.frame() %>%
   rownames_to_column() %>% 
  `colnames<-`(.[1,]) %>%
  slice(-1)

5.4 Exploratory Chi-square

library(broom)
set.seed(123)
df %>%
 select(family_type_cat, values_1:values_13) %>%
    mutate_at(vars( values_1:values_13),  ~case_when(
    . == "1" ~ "1-2",
    . == "2" ~ "1-2",
    . == "3"~ "3",
    . == "4" ~ "4-5",
    . == "5" ~ "4-5"
    
  )) %>%
  pivot_longer(-family_type_cat) %>%
  group_by(name) %>%
  nest() %>% 
  mutate(
    chi_sq_results = map(data, ~ stats::fisher.test(.x$family_type_cat, .x$value,simulate.p.value=TRUE)),
    tidied = map(chi_sq_results, tidy)
  ) %>%
  unnest(tidied)#%>% arrange(p.value)
set.seed(123)
df %>%
    mutate_at(vars( values_1:values_13),  ~case_when(
    . == "1" ~ "1-2",
    . == "2" ~ "1-2",
    . == "3"~ "3",
    . == "4" ~ "4-5",
    . == "5" ~ "4-5"
  )) %>%
  select(family_type_cat, values_1:values_13) %>% mutate_at(vars(values_1:values_13), ~as.factor(.)) %>%
  tableby(family_type_cat ~. , data = .,cat.test="fe", simulate.p.value=TRUE, B=2000) %>% summary(text = T, digits = 2) %>%
  as.data.frame()
lm(df$values_4 ~ df$family_type_cat) %>% apaTables::apa.aov.table()
## 
## 
## ANOVA results using df$values_4 as the dependent variable
##  
## 
##           Predictor     SS df     MS      F    p partial_eta2
##         (Intercept) 104.17  1 104.17 157.39 .000             
##  df$family_type_cat   5.76  3   1.92   2.90 .040          .10
##               Error  51.62 78   0.66                         
##  CI_90_partial_eta2
##                    
##          [.00, .19]
##                    
## 
## Note: Values in square brackets indicate the bounds of the 90% confidence interval for partial eta-squared
df %>%
  {gmodels::CrossTable(.$family_type_cat, .$values_7, prop.r = F,
                       prop.c = FALSE, prop.t = FALSE, fisher = T,
                       expected = TRUE)}
## Warning in chisq.test(t, correct = FALSE, ...): Aproximação do qui-quadrado
## pode estar incorreta
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |              Expected N |
## | Chi-square contribution |
## |-------------------------|
## 
##  
## Total Observations in Table:  82 
## 
##  
##                         | .$values_7 
##       .$family_type_cat |         1 |         2 |         3 |         4 |         5 | Row Total | 
## ------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
## homoaffective - mothers |         0 |         1 |         5 |         0 |         0 |         6 | 
##                         |     0.073 |     1.098 |     2.561 |     1.756 |     0.512 |           | 
##                         |     0.073 |     0.009 |     2.323 |     1.756 |     0.512 |           | 
## ------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
##            Monoparental |         0 |         7 |         3 |         6 |         2 |        18 | 
##                         |     0.220 |     3.293 |     7.683 |     5.268 |     1.537 |           | 
##                         |     0.220 |     4.174 |     2.854 |     0.102 |     0.140 |           | 
## ------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
##                 nuclear |         1 |         2 |        22 |        12 |         3 |        40 | 
##                         |     0.488 |     7.317 |    17.073 |    11.707 |     3.415 |           | 
##                         |     0.538 |     3.864 |     1.422 |     0.007 |     0.050 |           | 
## ------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
##               remarried |         0 |         5 |         5 |         6 |         2 |        18 | 
##                         |     0.220 |     3.293 |     7.683 |     5.268 |     1.537 |           | 
##                         |     0.220 |     0.885 |     0.937 |     0.102 |     0.140 |           | 
## ------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
##            Column Total |         1 |        15 |        35 |        24 |         7 |        82 | 
## ------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
## 
##  
## Statistics for All Table Factors
## 
## 
## Pearson's Chi-squared test 
## ------------------------------------------------------------
## Chi^2 =  20.32646     d.f. =  12     p =  0.06115709 
## 
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Alternative hypothesis: two.sided
## p =  0.01439403 
## 
## 

6 Dyads df and tableone

df %>%
  filter(valid == "complete", !is.na(complement)) %>%
  rowwise() %>%
  mutate(dyad_id = paste(sort(c(main, complement)), collapse = "-")) %>%
  ungroup() %>%
  distinct(dyad_id, .keep_all = TRUE) %>%
  count(family_type_cat)
#df %>%
#  filter(valid == "complete", !is.na(complement)) %>%
#  distinct(childs_name, .keep_all = TRUE) %>%
#  count(family_type_cat)
df %>%
  # Keep only rows marked as "complete"
  filter(valid == "complete") %>%
  
  # Remove rows where the complement (e.g., dyad pair) is missing
  filter(!is.na(complement)) %>%
  
  # Select relevant variables for analysis
  select(main, complement, childs_name, family_type_cat, child_age_months, 
         age_parent, education, people_living_together, number_of_children, 
         family_type_cat) %>%
  
  # Keep only one row per unique child name (remove duplicate children)
  distinct(childs_name, .keep_all = TRUE) %>% #here is important to not duplicate categorical variables' values
  
  # Sort rows alphabetically by child’s name
  arrange(childs_name) %>%
  
  # Generate descriptive summary statistics using tableby from arsenal package
  select(-childs_name) %>%
  tableby( ~ ., data = .) %>%
  
  # Output the summary in plain text format with 2 decimal places
  summary(text = TRUE, digits = 2) %>%
  
  # Convert the result into a data frame
  as.data.frame()

6.1 All parents average age

df %>%
  # Keep only rows marked as "complete"
  filter(valid == "complete") %>%
  
  # Remove rows where the complement (e.g., dyad pair) is missing
  filter(!is.na(complement)) %>%
  
  # Select relevant variables for analysis
    summarise(`Age of parent (M, SD, Range)` = sprintf("%.2f (%.2f), %d–%d",
                                                     mean(age_parent, na.rm = TRUE),
                                                     sd(age_parent, na.rm = TRUE),
                                                     min(age_parent, na.rm = TRUE),
                                                     max(age_parent, na.rm = TRUE)))

6.2 All children age

41.57 (28.12)

df %>%
  # Keep only rows marked as "complete"
  filter(valid == "complete") %>%
  
  # Remove rows where the complement (e.g., dyad pair) is missing
  filter(!is.na(complement)) %>%
  
  # Select relevant variables for analysis
  select(main, complement, childs_name, family_type_cat, child_age_months, 
         age_parent, education, people_living_together, number_of_children, 
         family_type_cat) %>%
  
  
  tableby( ~ ., data = .) %>%
  
  # Output the summary in plain text format with 2 decimal places
  summary(text = TRUE, digits = 2) %>%
  
  # Convert the result into a data frame
  as.data.frame()

7 Dyads 14 parents to parental values (list with 13 assertives)

7.1 Dataset 13 values

df_dyad = df %>%
  filter(valid == "complete") %>%
  filter(!is.na(complement)) %>%
  select(childs_name, parents_name, values_1:values_13) %>% 
  arrange(childs_name) %>%
  mutate(parents_name2 = rep(c("parent1", "parent2"), length.out = n())) %>% 
  select(parents_name2, everything()) %>%
  pivot_wider(id_cols = childs_name  ,names_from = parents_name2,  values_from = c(values_1:values_13)) %>%
  arrange(childs_name)
df_dyad

7.2 Dataset 13 values parent type (non homosexual)

# it`s possible to have two mothers or father. 
#Therefore, I`ll take a two-steps approach. First, I`ll use the unique data and then I`ll analyse these families later
#my final N here will be 12 as we have 2 homosexual families
df_dyad_parents = df %>%
  filter(valid == "complete") %>%
  filter(!is.na(complement)) %>%
  select(childs_name, parents_name, values_1:values_13) %>% 
  arrange(childs_name) %>%
  mutate(parents_name2 = rep(c("parent1", "parent2"), length.out = n())) %>%
  mutate(parent_type = case_when(
    parents_name == "monique" ~ "Mother",
    parents_name == "beatriz vargas" ~ "Mother",
    parents_name == "camila braz costa" ~ "Mother",
    parents_name == "monike" ~ "Mother",
    parents_name == "samira" ~ "Mother",
    parents_name == "ana clara mota" ~ "Mother",
    parents_name == "roberta" ~ "Mother",
    parents_name == "marina" ~ "Mother",
    parents_name == "fabiana ugarte" ~ "Mother",
    parents_name == "ana paula" ~ "Mother",
    parents_name == "nathalia reis de almeida" ~ "Mother",
    parents_name == "nayara" ~ "Mother",
    parents_name == "gabriela henrique mattos evangelista" ~ "Mother",
    parents_name == "claudia oliveira barreto" ~ "Mother",
    parents_name == "marcella wangler" ~ "Mother",
    parents_name == "aline" ~ "Mother",
    TRUE ~ "Father")) %>% 
  arrange(childs_name)

#add type of family
df_dyad_parents = left_join(
  df_dyad_parents,
  df %>% select(childs_name,parents_name, family_type_cat),
  by = c("childs_name","parents_name"),
  relationship = "many-to-many"
) %>% select(family_type_cat, everything())
df_dyad_parents
# Now have the pivot wider again
df_dyad_parents = df_dyad_parents %>%
  filter(family_type_cat != "homoaffective - mothers") %>%
  select(childs_name, parent_type, values_1:values_13) %>%
  pivot_wider(id_cols = childs_name  ,names_from = parent_type,  values_from = c(values_1:values_13),
              values_fn = mean) %>% #don't know why "isabela" is giving me a warning!
  arrange(childs_name)

df_dyad_parents

7.3 Dataset 13 values Items’ labels

item_labels <- tibble::tibble(
  item = as.character(1:13),
  item_content = c(
    "1_ Has good manners",
    "2_ Be interested in how and why things happen",
    "3_ Be responsible",
    "4_ Be considerate of others",
    "5_ Be tidy and clean",
    "6_ Act like a boy should act",
    "7_ Have self-control",
    "8_ Be a good student",
    "9_ Obey their parents",
    "10_ Have good sense and sound judgment",
    "11_ Have a good relationship with other children",
    "12_ Be honest",
    "13_ Try to if to succeed"
  )
)

df_dyad_parents <- df_dyad_parents %>%
  pivot_longer(-childs_name) %>%
  separate(name, into = c("value_1", "item", "parent")) %>%
  left_join(item_labels, by = "item") %>%
  select(-value_1)

df_dyad_parents

7.4 Correlation Values

#cor.test(df_dyad$values_1_parent1,df_dyad$values_1_parent2, method = "pearson")
#cor.test(df_dyad$values_2_parent1,df_dyad$values_2_parent2, method = "pearson")$estimate
#cor.test(df_dyad$values_3_parent1,df_dyad$values_3_parent2, method = "pearson")$estimate

# correlation value
for (i in 1:13) {
  cat("value", i)
  sapply ( cor.test(df_dyad[[paste0("values_",i,"_parent1")]],
              df_dyad[[paste0("values_",i,"_parent2")]], 
              use = "complete.obs")$estimate, print
  )
}
## value 1[1] 0.1766043
## value 2[1] 0.1443376
## value 3[1] 0.09443843
## value 4[1] 0.420084
## value 5[1] 0.2909932
## value 6[1] 0.4290839
## value 7[1] 0.1666667
## value 8[1] 0.5196746
## value 9[1] 0.2093059
## value 10[1] -0.08134892
## value 11[1] 0.4298876
## value 12[1] 0.1480466
## value 13[1] 0.2453267
# p value for all comparisons
for (i in 1:13) {
  cat("value", i)
  print ( cor.test(df_dyad[[paste0("values_",i,"_parent1")]],
              df_dyad[[paste0("values_",i,"_parent2")]], 
              use = "complete.obs")$p.value
  )
}
## value 1[1] 0.5458681
## value 2[1] 0.6225064
## value 3[1] 0.7481118
## value 4[1] 0.1347893
## value 5[1] 0.3128077
## value 6[1] 0.1257717
## value 7[1] 0.5690331
## value 8[1] 0.05682669
## value 9[1] 0.4726646
## value 10[1] 0.7821956
## value 11[1] 0.1249867
## value 12[1] 0.6134939
## value 13[1] 0.3978996
# confidence interval
for (i in 1:13) {
  print(  sapply ( cor.test(df_dyad[[paste0("values_",i,"_parent1")]],
                            df_dyad[[paste0("values_",i,"_parent2")]], 
                            use = "complete.obs")$conf.int, as.data.frame
  )
  )
}
## $`X[[i]]`
## [1] -0.3905729
## 
## $`X[[i]]`
## [1] 0.6465961
## 
## $`X[[i]]`
## [1] -0.4182745
## 
## $`X[[i]]`
## [1] 0.6269069
## 
## $`X[[i]]`
## [1] -0.4591476
## 
## $`X[[i]]`
## [1] 0.5951945
## 
## $`X[[i]]`
## [1] -0.1421873
## 
## $`X[[i]]`
## [1] 0.7773922
## 
## $`X[[i]]`
## [1] -0.2833312
## 
## $`X[[i]]`
## [1] 0.7116912
## 
## $`X[[i]]`
## [1] -0.1314136
## 
## $`X[[i]]`
## [1] 0.7816993
## 
## $`X[[i]]`
## [1] -0.3992154
## 
## $`X[[i]]`
## [1] 0.6405981
## 
## $`X[[i]]`
## [1] -0.01505633
## 
## $`X[[i]]`
## [1] 0.8232582
## 
## $`X[[i]]`
## [1] -0.3614094
## 
## $`X[[i]]`
## [1] 0.6659314
## 
## $`X[[i]]`
## [1] -0.5866092
## 
## $`X[[i]]`
## [1] 0.469495
## 
## $`X[[i]]`
## [1] -0.130445
## 
## $`X[[i]]`
## [1] 0.7820823
## 
## $`X[[i]]`
## [1] -0.4151425
## 
## $`X[[i]]`
## [1] 0.629202
## 
## $`X[[i]]`
## [1] -0.3279391
## 
## $`X[[i]]`
## [1] 0.6865422

7.5 Create df for correlation

#part 1  - Estimates
column = list()
for (i in 1:13) {
  column[i] =  cor.test(df_dyad[[paste0("values_",i,"_parent1")]],
              df_dyad[[paste0("values_",i,"_parent2")]], 
              use = "complete.obs")$estimate
  
}

df_dyad_cor = do.call(rbind,column) %>% as.data.frame()

# part 2 - confidence interval lower
column = list()
for (i in 1:13) {
  column[i] =  cor.test(df_dyad[[paste0("values_",i,"_parent1")]],
              df_dyad[[paste0("values_",i,"_parent2")]], 
              use = "complete.obs")$conf.int[[1]]
  
}
df_dyad_cor$conf_l = do.call(rbind,column)

# part 3 - confidence interval upper
column = list()
for (i in 1:13) {
  column[i] =  cor.test(df_dyad[[paste0("values_",i,"_parent1")]],
              df_dyad[[paste0("values_",i,"_parent2")]], 
              use = "complete.obs")$conf.int[2]
  
}
df_dyad_cor$conf_u = do.call(rbind,column)

# final adjustments
df_dyad_cor = df_dyad_cor %>% 
  mutate(item = row_number()) %>%
  rename(cor = V1) %>% select(item, everything())

df_dyad_cor

7.6 Create plot df for correlation

ggplot(df_dyad_cor, aes(x=item, y=cor)) + 
  geom_point(stat="identity", color="blue", 
       position=position_dodge()) +
  geom_errorbar(aes(ymin=conf_l, ymax=conf_u), width=.2,
            position=position_dodge(.9)) +
    scale_x_continuous(breaks = 1:13) +
  coord_flip()+
  theme_classic()
## Warning: Width not defined
## ℹ Set with `position_dodge(width = ...)`

7.7 Plot and table

df_dyad_parents %>%
  mutate(item = as.numeric(item)) %>%
  ggplot(., aes(x = item, y = value, fill = parent)) +
  geom_bar(stat = "summary", position = "dodge") +
  stat_summary(geom = "errorbar", position = position_dodge(width = 0.9),  width = 0.3) +
  scale_x_continuous(breaks = 1:13) +
  theme_classic()
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`

## Check which parent have higher scores

item Equal Father Mother 1 50.00% (6) 41.67% (5) 8.33% (1) #for example, from n = 12, 6 dont have different result 2 33.33% (4) 50.00% (6) 16.67% (2) 3 25.00% (3) 41.67% (5) 33.33% (4) 4 58.33% (7) 8.33% (1) 33.33% (4) 5 33.33% (4) 25.00% (3) 41.67% (5) 6 50.00% (6) 41.67% (5) 8.33% (1) 7 41.67% (5) 33.33% (4) 25.00% (3) 8 41.67% (5) 33.33% (4) 25.00% (3) 9 50.00% (6) 33.33% (4) 16.67% (2) 10 25.00% (3) 50.00% (6) 25.00% (3) #for example, from n = 12, fathers had higher results 11 66.67% (8) 16.67% (2) 16.67% (2) 12 75.00% (9) 8.33% (1) 16.67% (2) 13 33.33% (4) 41.67% (5) 25.00% (3) Total 44.87% (70) 32.69% (51) 22.44% (35)

df_dyad_parents %>%
  group_by(childs_name, item) %>%
  mutate(delta = value - lag(value)) %>%
  mutate(difference = if_else(delta == 0, "Equal", if_else(delta > 0, "Father", "Mother"))) %>%
  mutate(item2 = as.numeric(item)) %>% #if i transform items into numeric, it will be easier to arrange them later 
  ungroup() %>%
  filter(!is.na(difference)) %>%
  select(-c(parent, value, delta)) %>%
  tabyl(item2, difference) %>%
  adorn_totals(c("row")) %>%
  adorn_percentages("row") %>%
  adorn_pct_formatting(digits = 2) %>%
  adorn_ns() 
  #.[gtools::mixedorder(.$item), ] 
  #arrange(factor(item, levels = gtools::mixedsort(unique(item))))  # proper way

Now my freaking trick to not make more mistakes when sorting the data

left_join(
  df_dyad_parents %>%
    group_by(childs_name, item) %>%
    mutate(delta = value - lag(value)) %>%
    mutate(difference = if_else(delta == 0, "Equal", if_else(delta > 0, "Father", "Mother"))) %>%
    mutate(item2 = as.numeric(item)) %>% #if i transform items into numeric, it will be easier to arrange them later 
    ungroup() %>%
    filter(!is.na(difference)) %>%
    select(-c(parent, value, delta)) %>%
    tabyl(item2, difference) %>%
    adorn_totals(c("row")) %>%
    adorn_percentages("row") %>%
    adorn_pct_formatting(digits = 2) %>%
    adorn_ns() , 
  
  df_dyad_parents %>% select(item, item_content) %>% rename(item2=item) %>% distinct(item_content, .keep_all = T),
  by= "item2"
)
df_dyad_parents %>%
  group_by(childs_name, item) %>%
  mutate(delta = value - lag(value)) %>%
  mutate(difference = if_else(delta == 0, "Equal", if_else(delta > 0, "Father", "Mother"))) %>%
  ungroup() %>%
  filter(!is.na(difference)) %>%
  count(item, difference) %>%
  group_by(item) %>%
  mutate(perc = n / sum(n) * 100) %>%
  ungroup() %>%
  mutate(
    difference = factor(difference, levels = c("Equal", "Father", "Mother"))
  ) %>%
  
  left_join(
    df_dyad_parents %>%
      select(item, item_content) %>%
      distinct(item, .keep_all = TRUE),
    by = "item"
  ) %>%
  
  # Reorder item_content based on highest 'Equal' percentage
  group_by(item_content) %>%
  mutate(equal_perc = if_else(difference == "Equal", perc, NA_real_)) %>%
  fill(equal_perc, .direction = "downup") %>%
  ungroup() %>%
  mutate(item_content = fct_reorder(gsub(".*_", "", item_content), equal_perc, .desc = FALSE)) %>%
  
  ggplot(aes(x = item_content, y = perc, fill = difference, label = paste0(round(perc, 1), "%"))) +
  geom_col(position = position_stack(reverse = TRUE)) +
  geom_text(position = position_stack(vjust = 0.5, reverse = TRUE), color = "white", size = 6) +
  coord_flip() +
  labs(x = "", y = "Percentage", fill = "Parent with Higher Score",
       title = "Parental Differences in Item Endorsement") +
  scale_fill_manual(values = c("Equal" = "#9BBB59", "Father" = "#4F81BD", "Mother" = "#C0504D")) +
  
  theme_minimal(base_size = 13) + theme(legend.position = "bottom")+ theme(axis.text.y = element_text(margin = margin(r = -20)))

8 Dyads 10 Socialization goals

8.1 Dataset 10 goals

df_dyad_goals = df %>%
  filter(valid == "complete") %>%
  filter(!is.na(complement)) %>%
  select(childs_name, parents_name, socialization_goal_1:socialization_goal_10) %>% 
  arrange(childs_name) %>%
  mutate(parents_name2 = rep(c("parent1", "parent2"), length.out = n())) %>% 
  select(parents_name2, everything()) %>%
  pivot_wider(id_cols = childs_name  ,names_from = parents_name2,  values_from = c(socialization_goal_1:socialization_goal_10)) %>%
  arrange(childs_name)
df_dyad_goals

8.2 Dataset 10 goals parent type (non homosexual

# it`s possible to have two mothers or father. 
#Therefore, I`ll take a two-steps approach. First, I`ll use the unique data and then I`ll analyse these families later
#my final N here will be 12 as we have 2 homosexual families
df_dyad_goals_parents = df %>%
  filter(valid == "complete") %>%
  filter(!is.na(complement)) %>%
  select(childs_name, parents_name, socialization_goal_1:socialization_goal_10) %>% 
  arrange(childs_name) %>%
  mutate(parents_name2 = rep(c("parent1", "parent2"), length.out = n())) %>%
  mutate(parent_type = case_when(
    parents_name == "monique" ~ "Mother",
    parents_name == "beatriz vargas" ~ "Mother",
    parents_name == "camila braz costa" ~ "Mother",
    parents_name == "monike" ~ "Mother",
    parents_name == "samira" ~ "Mother",
    parents_name == "ana clara mota" ~ "Mother",
    parents_name == "roberta" ~ "Mother",
    parents_name == "marina" ~ "Mother",
    parents_name == "fabiana ugarte" ~ "Mother",
    parents_name == "ana paula" ~ "Mother",
    parents_name == "nathalia reis de almeida" ~ "Mother",
    parents_name == "nayara" ~ "Mother",
    parents_name == "gabriela henrique mattos evangelista" ~ "Mother",
    parents_name == "claudia oliveira barreto" ~ "Mother",
    parents_name == "marcella wangler" ~ "Mother",
    parents_name == "aline" ~ "Mother",
    TRUE ~ "Father")) %>% 
  arrange(childs_name)

#add type of family
df_dyad_goals_parents = left_join(
  df_dyad_goals_parents,
  df %>% select(childs_name,parents_name, family_type_cat),
  by = c("childs_name","parents_name"),
  relationship = "many-to-many"
) %>% select(family_type_cat, everything())
df_dyad_goals_parents
# Now have the pivot wider again
df_dyad_goals_parents = df_dyad_goals_parents %>%
  filter(family_type_cat != "homoaffective - mothers") %>%
  select(childs_name, parent_type, socialization_goal_1:socialization_goal_10) %>%
  pivot_wider(id_cols = childs_name  ,names_from = parent_type,  values_from = c(socialization_goal_1:socialization_goal_10),
              values_fn = mean) %>% #don't know why "isabela" is giving me a warning!
  arrange(childs_name)


df_dyad_goals_parents

8.3 Dataset 10 goals parent type Items’ labels

item_labels <- tibble::tibble(
  item = as.character(1:10),
  item_content = c(
    "1_ Be able to control emotions",
    "2_ Develop independence",
    "3_ Develop self-trust",
    "4_ Know how to obey their parents",
    "5_ Know how to respect older people",
    "6_ Show care for the well-being of others",
    "7_ Develop a sense of self-esteem",
    "8_ Learn to cheer others up (when they are sad)",
    "9_ Develop competitiveness",
    "10_ Develop a sense of identity"
  )
)

df_dyad_goals_parents <- df_dyad_goals_parents %>%
  pivot_longer(-childs_name) %>%
  separate(name, into = c("value_1", "nothing", "item", "parent")) %>%
  left_join(item_labels, by = "item") %>%
  select(-value_1)

df_dyad_goals_parents

8.4 Correlation Values

#cor.test(df_dyad_goals$socialization_goal_1_parent1,df_dyad_goals$socialization_goal_1_parent2, method = "pearson")
#cor.test(df_dyad_goals$socialization_goal_2_parent1,df_dyad_goals$socialization_goal_2_parent2, method = "pearson")
#cor.test(df_dyad_goals$socialization_goal_3_parent1,df_dyad_goals$socialization_goal_3_parent2, method = "pearson")
for (i in 1:10) {
  cat("value", i)
  sapply ( cor.test(df_dyad_goals[[paste0("socialization_goal_",i,"_parent1")]],
              df_dyad_goals[[paste0("socialization_goal_",i,"_parent2")]], 
              use = "complete.obs")$estimate, print
  )
}
## value 1[1] 0.2074435
## value 2[1] -0.1957122
## value 3[1] -0.3233265
## value 4[1] 0.2765913
## value 5[1] 0.6710927
## value 6[1] 0.5241272
## value 7[1] -0.2144841
## value 8[1] 0.2552305
## value 9[1] 0.139341
## value 10[1] 0.586368
for (i in 1:10) {
  cat("value", i)
  print ( cor.test(df_dyad_goals[[paste0("socialization_goal_",i,"_parent1")]],
              df_dyad_goals[[paste0("socialization_goal_",i,"_parent2")]], 
              use = "complete.obs")$p.value
  )
}
## value 1[1] 0.4767027
## value 2[1] 0.50251
## value 3[1] 0.2594845
## value 4[1] 0.3384273
## value 5[1] 0.008600145
## value 6[1] 0.0543684
## value 7[1] 0.4615237
## value 8[1] 0.3784987
## value 9[1] 0.6347252
## value 10[1] 0.0275307
for (i in 1:10) {
  print(  sapply ( cor.test(df_dyad_goals[[paste0("socialization_goal_",i,"_parent1")]],
                            df_dyad_goals[[paste0("socialization_goal_",i,"_parent2")]], 
                            use = "complete.obs")$conf.int, as.data.frame
  )
  )
}
## $`X[[i]]`
## [1] -0.3631008
## 
## $`X[[i]]`
## [1] 0.6648465
## 
## $`X[[i]]`
## [1] -0.6579677
## 
## $`X[[i]]`
## [1] 0.3736695
## 
## $`X[[i]]`
## [1] -0.7288683
## 
## $`X[[i]]`
## [1] 0.2501697
## 
## $`X[[i]]`
## [1] -0.2976728
## 
## $`X[[i]]`
## [1] 0.7038746
## 
## $`X[[i]]`
## [1] 0.2182112
## 
## $`X[[i]]`
## [1] 0.8861445
## 
## $`X[[i]]`
## [1] -0.008937861
## 
## $`X[[i]]`
## [1] 0.8252202
## 
## $`X[[i]]`
## [1] -0.6689379
## 
## $`X[[i]]`
## [1] 0.3566866
## 
## $`X[[i]]`
## [1] -0.3184772
## 
## $`X[[i]]`
## [1] 0.6920875
## 
## $`X[[i]]`
## [1] -0.4224725
## 
## $`X[[i]]`
## [1] 0.6238019
## 
## $`X[[i]]`
## [1] 0.08098367
## 
## $`X[[i]]`
## [1] 0.8519067

8.5 Create df for correlation

#part 1  - Estimates
column = list()
for (i in 1:10) {
  column[i] =  cor.test(df_dyad_goals[[paste0("socialization_goal_",i,"_parent1")]],
              df_dyad_goals[[paste0("socialization_goal_",i,"_parent2")]], 
              use = "complete.obs")$estimate
  
}

df_dyad_goals_cor = do.call(rbind,column) %>% as.data.frame()

# part 2 - confidence interval lower
column = list()
for (i in 1:10) {
  column[i] =  cor.test(df_dyad_goals[[paste0("socialization_goal_",i,"_parent1")]],
              df_dyad_goals[[paste0("socialization_goal_",i,"_parent2")]], 
              use = "complete.obs")$conf.int[[1]]
  
}
df_dyad_goals_cor$conf_l = do.call(rbind,column)

# part 3 - confidence interval upper
column = list()
for (i in 1:10) {
  column[i] =  cor.test(df_dyad_goals[[paste0("socialization_goal_",i,"_parent1")]],
              df_dyad_goals[[paste0("socialization_goal_",i,"_parent2")]], 
              use = "complete.obs")$conf.int[2]
  
}
df_dyad_goals_cor$conf_u = do.call(rbind,column)

# final adjustments
df_dyad_goals_cor = df_dyad_goals_cor %>% 
  mutate(item = row_number()) %>%
  rename(cor = V1) %>% select(item, everything())
df_dyad_goals_cor

8.6 Plot and table

df_dyad_goals_parents %>%
  mutate(item = as.numeric(item))%>%
  ggplot(., aes(x = item, y = value, fill = parent))+
  geom_bar(stat = "summary", position = "dodge") +
  stat_summary(geom = "errorbar", position = position_dodge(width = 0.9),  width = 0.3) +
  scale_x_continuous(breaks = 1:10) +
  theme_classic()
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`

## Check which parent have higher scores

df_dyad_goals_parents %>%
  group_by(childs_name, item) %>%
  mutate(delta = value-lag(value)) %>%
  #definy which parent has the higher result
  mutate(difference = if_else(delta == 0, "Equal", if_else(delta > 0, "Father", "Mother"))) %>%
  ungroup() %>%
  filter(!is.na(difference)) %>%
  tabyl(item, difference)  %>%
  adorn_totals(c("row")) %>%
    adorn_percentages("row") %>%
  adorn_pct_formatting(digits = 2) %>%
  adorn_ns() %>%
  .[gtools::mixedorder(.$item), ] 
df_dyad_goals_parents %>%
  group_by(childs_name, item) %>%
  mutate(delta = value - lag(value)) %>%
  mutate(difference = if_else(delta == 0, "Equal", if_else(delta > 0, "Father", "Mother"))) %>%
  ungroup() %>%
  filter(!is.na(difference)) %>%
  count(item, difference) %>%
  group_by(item) %>%
  mutate(perc = n / sum(n) * 100) %>%
  ungroup() %>%
  mutate(
    difference = factor(difference, levels = c("Equal", "Father", "Mother"))
  ) %>%
  
  left_join(
    df_dyad_goals_parents %>%
      select(item, item_content) %>%
      distinct(item, .keep_all = TRUE),
    by = "item"
  ) %>%
  
  # Reorder item_content based on highest 'Equal' percentage
  group_by(item_content) %>%
  mutate(equal_perc = if_else(difference == "Equal", perc, NA_real_)) %>%
  fill(equal_perc, .direction = "downup") %>%
  ungroup() %>%
  mutate(item_content = fct_reorder(gsub(".*_", "", item_content), equal_perc, .desc = FALSE)) %>%
  
  ggplot(aes(x = item_content, y = perc, fill = difference, label = paste0(round(perc, 1), "%"))) +
  geom_col(position = position_stack(reverse = TRUE)) +
  geom_text(position = position_stack(vjust = 0.5, reverse = TRUE), color = "white", size = 6) +
  coord_flip() +
  labs(x = "", y = "Percentage", fill = "Parent with Higher Score",
       title = "Parental Differences in Item Endorsement") +
  scale_fill_manual(values = c("Equal" = "#9BBB59", "Father" = "#4F81BD", "Mother" = "#C0504D")) +
  
  theme_minimal(base_size = 13) + theme(legend.position = "bottom")+ theme(axis.text.y = element_text(margin = margin(r = -20)))