knitr::opts_chunk$set(echo = TRUE, comment="")
library(readxl)
Durias<- read_excel("C:/Psychology/Mejorada/data1.xlsx")
Durias
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
Durias<-Durias%>%
  mutate(RSES1.1=recode(`RSES 1`, 
                          "Strongly Disagree" = "0", "Disagree" ="1", "Agree"="2", "Strongly Agree" = "3"))%>%
  mutate(RSES1.3=recode(`RSES 3`, 
                          "Strongly Disagree" = "0", "Disagree" ="1", "Agree"="2", "Strongly Agree" = "3"))%>%
  mutate(RSES1.4=recode(`RSES 4`, 
                          "Strongly Disagree" = "0", "Disagree" ="1", "Agree"="2", "Strongly Agree" = "3"))%>%
  mutate(RSES1.7=recode(`RSES 7`, 
                          "Strongly Disagree" = "0", "Disagree" ="1", "Agree"="2", "Strongly Agree" = "3"))%>%
  mutate(RSES1.10=recode(`RSES 10`, 
                          "Strongly Disagree" = "0", "Disagree" ="1", "Agree"="2", "Strongly Agree" = "3"))%>%
  mutate(RSES1.2=recode(`RSES 2`, 
                          "Strongly Disagree" = "3", "Disagree" ="2", "Agree"="1", "Strongly Agree" = "0"))%>%
  mutate(RSES1.5=recode(`RSES 5`, 
                          "Strongly Disagree" = "3", "Disagree" ="2", "Agree"="1", "Strongly Agree" = "0"))%>%
  mutate(RSES1.6=recode(`RSES 6`, 
                          "Strongly Disagree" = "3", "Disagree" ="2", "Agree"="1", "Strongly Agree" = "0"))%>%
  mutate(RSES1.8=recode(`RSES 8`, 
                          "Strongly Disagree" = "3", "Disagree" ="2", "Agree"="1", "Strongly Agree" = "0"))%>%
  mutate(RSES1.9=recode(`RSES 9`, 
                          "Strongly Disagree" = "3", "Disagree" ="2", "Agree"="1", "Strongly Agree" = "0"))
Durias
Durias$RSES1.1=as.numeric(Durias$RSES1.1)
Durias$RSES1.2=as.numeric(Durias$RSES1.2)
Durias$RSES1.3=as.numeric(Durias$RSES1.3)
Durias$RSES1.4=as.numeric(Durias$RSES1.4)
Durias$RSES1.5=as.numeric(Durias$RSES1.5)
Durias$RSES1.6=as.numeric(Durias$RSES1.6)
Durias$RSES1.7=as.numeric(Durias$RSES1.7)
Durias$RSES1.8=as.numeric(Durias$RSES1.8)
Durias$RSES1.9=as.numeric(Durias$RSES1.9)
Durias$RSES1.10=as.numeric(Durias$RSES1.10)
Durias$SumSelfEsteem<-Durias$RSES1.1+Durias$RSES1.2+Durias$RSES1.3+Durias$RSES1.4+Durias$RSES1.5+ Durias$RSES1.6+Durias$RSES1.7+Durias$RSES1.8+Durias$RSES1.9+Durias$RSES1.10
Durias<-Durias%>%
 mutate(`Self-esteem Scale` = ifelse(SumSelfEsteem<=14,"Low self-esteem", 
                   ifelse(SumSelfEsteem>=25, "High self-esteem", "Normal")))%>%
 mutate(`Age Group` = ifelse(Age<=18, "at most 18 years old", "19 years old and above"))
summary(Durias$Age)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  16.00   18.00   18.00   18.22   18.00   22.00 

Socio-Demographic Profile

#Type of Family

library(dplyr)
Durias%>%
  group_by(`Type of Family`, `Self-esteem Scale`) %>%
  summarise(count=n())%>%
  mutate(Percentage =count/sum(count))
`summarise()` has grouped output by 'Type of Family'. You can override using
the `.groups` argument.

#Age

#Summary statistics
Durias%>%
  group_by(`Age Group`, `Self-esteem Scale`) %>%
  summarise(count=n())%>%
  mutate(Percentage =count/sum(count))
`summarise()` has grouped output by 'Age Group'. You can override using the
`.groups` argument.
Durias<-Durias%>%
 mutate(`Summary Scale` = ifelse(`Self-esteem Scale`== "Normal", "Normal", "Non-normal"))

Sex

#Summary statistics
Durias%>%
  group_by(Sex, `Self-esteem Scale`) %>%
  summarise(count=n())%>%
  mutate(Percentage =count/sum(count))
`summarise()` has grouped output by 'Sex'. You can override using the `.groups`
argument.

2 2. What is the self-esteem level of the respondents’ from intact and broken families?

#Summary statistics
Durias%>%
  group_by(`Type of Family`, `Self-esteem Scale`) %>%
  summarise(count=n())%>%
  mutate(Percentage =count/sum(count))
`summarise()` has grouped output by 'Type of Family'. You can override using
the `.groups` argument.
Durias%>%
  group_by(`Type of Family`)%>%
  summarise(Frequency=n(), Mean = mean(SumSelfEsteem), `Standard Deviation` = sd(SumSelfEsteem))

3. Is there a significant difference in the self-esteem level of the respondents when grouped according to

  1. Type of family?

Test for equality of variances

res.ftest <- var.test(Durias$SumSelfEsteem ~ Durias$`Type of Family`)
res.ftest

    F test to compare two variances

data:  Durias$SumSelfEsteem by Durias$`Type of Family`
F = 0.98022, num df = 29, denom df = 29, p-value = 0.9575
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.4665496 2.0594353
sample estimates:
ratio of variances 
         0.9802187 

The variances are equal since the p-value exceeds 0.05.

Test for Significant Differnce in the self-esteem level of the respondents when grouped according to;

  1. Type of family?
t.test(Durias$SumSelfEsteem~Durias$`Type of Family`, var.equal = TRUE)

    Two Sample t-test

data:  Durias$SumSelfEsteem by Durias$`Type of Family`
t = -1.6432, df = 58, p-value = 0.1057
alternative hypothesis: true difference in means between group Broken Family and group Intact Family is not equal to 0
95 percent confidence interval:
 -3.4751380  0.3418047
sample estimates:
mean in group Broken Family mean in group Intact Family 
                   15.86667                    17.43333 

The result shows that the self-esteem between intact and broken family does not statistically differ since the p-value=0.2901 exceeds the 0.05 level of significance.

4. Is there a significant relationship between the respondents’ self-esteem level and;

  1. Sex
  2. Age?
Durias<-Durias%>%
 mutate(`Summary Scale` = ifelse(`Self-esteem Scale`== "Normal", "Normal", "Non-normal"))

Sex and Self-esteem Level

library(gmodels)
Crosstabdata<-CrossTable(Durias$Sex, Durias$`Summary Scale`)

 
   Cell Contents
|-------------------------|
|                       N |
| Chi-square contribution |
|           N / Row Total |
|           N / Col Total |
|         N / Table Total |
|-------------------------|

 
Total Observations in Table:  60 

 
             | Durias$`Summary Scale` 
  Durias$Sex | Non-normal |     Normal |  Row Total | 
-------------|------------|------------|------------|
      Female |         12 |         23 |         35 | 
             |      0.438 |      0.173 |            | 
             |      0.343 |      0.657 |      0.583 | 
             |      0.706 |      0.535 |            | 
             |      0.200 |      0.383 |            | 
-------------|------------|------------|------------|
        Male |          5 |         20 |         25 | 
             |      0.613 |      0.242 |            | 
             |      0.200 |      0.800 |      0.417 | 
             |      0.294 |      0.465 |            | 
             |      0.083 |      0.333 |            | 
-------------|------------|------------|------------|
Column Total |         17 |         43 |         60 | 
             |      0.283 |      0.717 |            | 
-------------|------------|------------|------------|

 
Crosstabdata
$t
        y
x        Non-normal Normal
  Female         12     23
  Male            5     20

$prop.row
        y
x        Non-normal    Normal
  Female  0.3428571 0.6571429
  Male    0.2000000 0.8000000

$prop.col
        y
x        Non-normal    Normal
  Female  0.7058824 0.5348837
  Male    0.2941176 0.4651163

$prop.tbl
        y
x        Non-normal     Normal
  Female 0.20000000 0.38333333
  Male   0.08333333 0.33333333
table2=matrix(c(23,20, 12, 5) ,ncol=2) 
colnames(table2)=c("Normal", "Non-normal") 
rownames(table2)=c("Female", "Male")
table2
       Normal Non-normal
Female     23         12
Male       20          5
chisq.test(table2)

    Pearson's Chi-squared test with Yates' continuity correction

data:  table2
X-squared = 0.84659, df = 1, p-value = 0.3575

There is no significant relationship between sex and self-esteem level.

Age and Self-esteem Level

library(gmodels)
Crosstabdata<-CrossTable(Durias$`Age Group`, Durias$`Summary Scale`)

 
   Cell Contents
|-------------------------|
|                       N |
| Chi-square contribution |
|           N / Row Total |
|           N / Col Total |
|         N / Table Total |
|-------------------------|

 
Total Observations in Table:  60 

 
                       | Durias$`Summary Scale` 
    Durias$`Age Group` | Non-normal |     Normal |  Row Total | 
-----------------------|------------|------------|------------|
19 years old and above |          4 |         10 |         14 | 
                       |      0.000 |      0.000 |            | 
                       |      0.286 |      0.714 |      0.233 | 
                       |      0.235 |      0.233 |            | 
                       |      0.067 |      0.167 |            | 
-----------------------|------------|------------|------------|
  at most 18 years old |         13 |         33 |         46 | 
                       |      0.000 |      0.000 |            | 
                       |      0.283 |      0.717 |      0.767 | 
                       |      0.765 |      0.767 |            | 
                       |      0.217 |      0.550 |            | 
-----------------------|------------|------------|------------|
          Column Total |         17 |         43 |         60 | 
                       |      0.283 |      0.717 |            | 
-----------------------|------------|------------|------------|

 
Crosstabdata
$t
                        y
x                        Non-normal Normal
  19 years old and above          4     10
  at most 18 years old           13     33

$prop.row
                        y
x                        Non-normal    Normal
  19 years old and above  0.2857143 0.7142857
  at most 18 years old    0.2826087 0.7173913

$prop.col
                        y
x                        Non-normal    Normal
  19 years old and above  0.2352941 0.2325581
  at most 18 years old    0.7647059 0.7674419

$prop.tbl
                        y
x                        Non-normal     Normal
  19 years old and above 0.06666667 0.16666667
  at most 18 years old   0.21666667 0.55000000
table2=matrix(c(33,10, 13, 4) ,ncol=2) 
colnames(table2)=c("Normal", "Non-normal") 
rownames(table2)=c("at most 18 years old", "at least 19 years old")
table2
                      Normal Non-normal
at most 18 years old      33         13
at least 19 years old     10          4
chisq.test(table2)
Warning in chisq.test(table2): Chi-squared approximation may be incorrect

    Pearson's Chi-squared test with Yates' continuity correction

data:  table2
X-squared = 1.3521e-30, df = 1, p-value = 1

There is no significant relationship between age and self-esteem level.