library(readxl)
## Warning: package 'readxl' was built under R version 4.1.3
Durias<- read_excel("D:/COLLEGE 3RD YEAR/2nd SEMESTER/STAT 50 STATISTICAL SOFTWARE/FINAL/Final Term Activity/data1.xlsx")
Durias
## # A tibble: 60 x 14
##    Respondent `Type of Family` Sex     Age `RSES 1`   `RSES 2` `RSES 3` `RSES 4`
##         <dbl> <chr>            <chr> <dbl> <chr>      <chr>    <chr>    <chr>   
##  1          1 Intact           Male     15 Agree      Agree    Agree    Agree   
##  2          2 Intact           Male     16 Agree      Agree    Agree    Agree   
##  3          3 Intact           Male     17 Agree      Agree    Agree    Agree   
##  4          4 Intact           Male     16 Agree      Agree    Strongl~ Agree   
##  5          5 Intact           Male     16 Agree      Disagree Agree    Agree   
##  6          6 Intact           Male     14 Strongly ~ Agree    Agree    Agree   
##  7          7 Intact           Male     14 Agree      Strongl~ Agree    Disagree
##  8          8 Intact           Male     16 Agree      Agree    Agree    Agree   
##  9          9 Intact           Male     16 Strongly ~ Agree    Agree    Agree   
## 10         10 Intact           Male     14 Agree      Disagree Agree    Agree   
## # ... with 50 more rows, and 6 more variables: `RSES 5` <chr>, `RSES 6` <chr>,
## #   `RSES 7` <chr>, `RSES 8` <chr>, `RSES 9` <chr>, `RSES 10` <chr>
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
## # A tibble: 60 x 24
##    Respondent `Type of Family` Sex     Age `RSES 1`   `RSES 2` `RSES 3` `RSES 4`
##         <dbl> <chr>            <chr> <dbl> <chr>      <chr>    <chr>    <chr>   
##  1          1 Intact           Male     15 Agree      Agree    Agree    Agree   
##  2          2 Intact           Male     16 Agree      Agree    Agree    Agree   
##  3          3 Intact           Male     17 Agree      Agree    Agree    Agree   
##  4          4 Intact           Male     16 Agree      Agree    Strongl~ Agree   
##  5          5 Intact           Male     16 Agree      Disagree Agree    Agree   
##  6          6 Intact           Male     14 Strongly ~ Agree    Agree    Agree   
##  7          7 Intact           Male     14 Agree      Strongl~ Agree    Disagree
##  8          8 Intact           Male     16 Agree      Agree    Agree    Agree   
##  9          9 Intact           Male     16 Strongly ~ Agree    Agree    Agree   
## 10         10 Intact           Male     14 Agree      Disagree Agree    Agree   
## # ... with 50 more rows, and 16 more variables: `RSES 5` <chr>, `RSES 6` <chr>,
## #   `RSES 7` <chr>, `RSES 8` <chr>, `RSES 9` <chr>, `RSES 10` <chr>,
## #   RSES1.1 <chr>, RSES1.3 <chr>, RSES1.4 <chr>, RSES1.7 <chr>, RSES1.10 <chr>,
## #   RSES1.2 <chr>, RSES1.5 <chr>, RSES1.6 <chr>, RSES1.8 <chr>, RSES1.9 <chr>
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
## # A tibble: 60 x 25
##    Respondent `Type of Family` Sex     Age `RSES 1`   `RSES 2` `RSES 3` `RSES 4`
##         <dbl> <chr>            <chr> <dbl> <chr>      <chr>    <chr>    <chr>   
##  1          1 Intact           Male     15 Agree      Agree    Agree    Agree   
##  2          2 Intact           Male     16 Agree      Agree    Agree    Agree   
##  3          3 Intact           Male     17 Agree      Agree    Agree    Agree   
##  4          4 Intact           Male     16 Agree      Agree    Strongl~ Agree   
##  5          5 Intact           Male     16 Agree      Disagree Agree    Agree   
##  6          6 Intact           Male     14 Strongly ~ Agree    Agree    Agree   
##  7          7 Intact           Male     14 Agree      Strongl~ Agree    Disagree
##  8          8 Intact           Male     16 Agree      Agree    Agree    Agree   
##  9          9 Intact           Male     16 Strongly ~ Agree    Agree    Agree   
## 10         10 Intact           Male     14 Agree      Disagree Agree    Agree   
## # ... with 50 more rows, and 17 more variables: `RSES 5` <chr>, `RSES 6` <chr>,
## #   `RSES 7` <chr>, `RSES 8` <chr>, `RSES 9` <chr>, `RSES 10` <chr>,
## #   RSES1.1 <dbl>, RSES1.3 <dbl>, RSES1.4 <dbl>, RSES1.7 <dbl>, RSES1.10 <dbl>,
## #   RSES1.2 <dbl>, RSES1.5 <dbl>, RSES1.6 <dbl>, RSES1.8 <dbl>, RSES1.9 <dbl>,
## #   SumSelfEsteem <dbl>
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"))
Durias$Age
##  [1] 15 16 17 16 16 14 14 16 16 14 15 15 13 16 16 13 15 16 16 14 16 15 14 12 16
## [26] 13 15 17 16 14 15 15 16 16 15 15 14 16 12 13 16 14 13 13 16 15 13 16 14 14
## [51] 12 14 17 13 16 14 15 16 16 14
summary(Durias$Age)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   12.00   14.00   15.00   14.82   16.00   17.00

1. What is the socio-demographic profile of the respondents according to:

a. Type of Family(Intact/Broken)

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.
## # A tibble: 5 x 4
## # Groups:   Type of Family [2]
##   `Type of Family` `Self-esteem Scale` count Percentage
##   <chr>            <chr>               <int>      <dbl>
## 1 Broken           High self-esteem        2     0.0667
## 2 Broken           Low self-esteem        16     0.533 
## 3 Broken           Normal                 12     0.4   
## 4 Intact           Low self-esteem         9     0.3   
## 5 Intact           Normal                 21     0.7

b. 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.
## # A tibble: 6 x 4
## # Groups:   Sex [2]
##   Sex    `Self-esteem Scale` count Percentage
##   <chr>  <chr>               <int>      <dbl>
## 1 Female High self-esteem        1     0.0270
## 2 Female Low self-esteem        17     0.459 
## 3 Female Normal                 19     0.514 
## 4 Male   High self-esteem        1     0.0435
## 5 Male   Low self-esteem         8     0.348 
## 6 Male   Normal                 14     0.609

c. 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.
## # A tibble: 3 x 4
## # Groups:   Age Group [1]
##   `Age Group`          `Self-esteem Scale` count Percentage
##   <chr>                <chr>               <int>      <dbl>
## 1 at most 18 years old High self-esteem        2     0.0333
## 2 at most 18 years old Low self-esteem        25     0.417 
## 3 at most 18 years old Normal                 33     0.55
Durias<-Durias%>%
 mutate(`Summary Scale` = ifelse(`Self-esteem Scale`== "Normal", "Normal", "Non-normal"))

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.
## # A tibble: 5 x 4
## # Groups:   Type of Family [2]
##   `Type of Family` `Self-esteem Scale` count Percentage
##   <chr>            <chr>               <int>      <dbl>
## 1 Broken           High self-esteem        2     0.0667
## 2 Broken           Low self-esteem        16     0.533 
## 3 Broken           Normal                 12     0.4   
## 4 Intact           Low self-esteem         9     0.3   
## 5 Intact           Normal                 21     0.7
Durias%>%
  group_by(`Type of Family`)%>%
  summarise(Frequency=n(), Mean = mean(SumSelfEsteem), `Standard Deviation` = sd(SumSelfEsteem))
## # A tibble: 2 x 4
##   `Type of Family` Frequency  Mean `Standard Deviation`
##   <chr>                <int> <dbl>                <dbl>
## 1 Broken                  30  15.1                 4.40
## 2 Intact                  30  16.6                 3.09

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

a. 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 = 2.0215, num df = 29, denom df = 29, p-value = 0.06286
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.9621684 4.2471879
## sample estimates:
## ratio of variances 
##           2.021512

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:

a. 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.4943, df = 58, p-value = 0.1405
## alternative hypothesis: true difference in means between group Broken and group Intact is not equal to 0
## 95 percent confidence interval:
##  -3.4313042  0.4979709
## sample estimates:
## mean in group Broken mean in group Intact 
##             15.10000             16.56667

Interpretation

      The result shows that the self-esteem between intact and broken family does not statistically differ since the p-value = 0.1405 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)
## Warning: package 'gmodels' was built under R version 4.1.3
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 |         18 |         19 |         37 | 
##              |      0.109 |      0.090 |            | 
##              |      0.486 |      0.514 |      0.617 | 
##              |      0.667 |      0.576 |            | 
##              |      0.300 |      0.317 |            | 
## -------------|------------|------------|------------|
##         Male |          9 |         14 |         23 | 
##              |      0.176 |      0.144 |            | 
##              |      0.391 |      0.609 |      0.383 | 
##              |      0.333 |      0.424 |            | 
##              |      0.150 |      0.233 |            | 
## -------------|------------|------------|------------|
## Column Total |         27 |         33 |         60 | 
##              |      0.450 |      0.550 |            | 
## -------------|------------|------------|------------|
## 
## 
Crosstabdata
## $t
##         y
## x        Non-normal Normal
##   Female         18     19
##   Male            9     14
## 
## $prop.row
##         y
## x        Non-normal    Normal
##   Female  0.4864865 0.5135135
##   Male    0.3913043 0.6086957
## 
## $prop.col
##         y
## x        Non-normal    Normal
##   Female  0.6666667 0.5757576
##   Male    0.3333333 0.4242424
## 
## $prop.tbl
##         y
## x        Non-normal    Normal
##   Female  0.3000000 0.3166667
##   Male    0.1500000 0.2333333
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

Interpretation

      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 |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  60 
## 
##  
##                      | Durias$`Summary Scale` 
##   Durias$`Age Group` | Non-normal |     Normal |  Row Total | 
## ---------------------|------------|------------|------------|
## at most 18 years old |         27 |         33 |         60 | 
##                      |      0.450 |      0.550 |            | 
## ---------------------|------------|------------|------------|
##         Column Total |         27 |         33 |         60 | 
## ---------------------|------------|------------|------------|
## 
## 
Crosstabdata
## $t
##                       y
## x                      Non-normal Normal
##   at most 18 years old         27     33
## 
## $prop.row
##                       y
## x                      Non-normal Normal
##   at most 18 years old       0.45   0.55
## 
## $prop.col
##                       y
## x                      Non-normal Normal
##   at most 18 years old          1      1
## 
## $prop.tbl
##                       y
## x                      Non-normal Normal
##   at most 18 years old       0.45   0.55
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

Interpretation

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