library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
mydata <- read_delim("C:\\Users\\abhir\\OneDrive\\Documents\\luddy\\H510-Stats,R\\adult.csv", delim = ",")
## Rows: 32561 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): Work-Class, Education, Marital Status, Occupation, Relationship, Ra...
## dbl (6): Age, Fnl_Wgt, Education_Level, Capital_Gain, Capital_Loss, hrs_week
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
mydata
## # A tibble: 32,561 × 15
## Age `Work-Class` Fnl_Wgt Education Education_Level `Marital Status`
## <dbl> <chr> <dbl> <chr> <dbl> <chr>
## 1 39 " State-gov" 77516 " Bachelo… 13 " Never-married"
## 2 50 " Self-emp-not-inc" 83311 " Bachelo… 13 " Married-civ-s…
## 3 38 " Private" 215646 " HS-grad" 9 " Divorced"
## 4 53 " Private" 234721 " 11th" 7 " Married-civ-s…
## 5 28 " Private" 338409 " Bachelo… 13 " Married-civ-s…
## 6 37 " Private" 284582 " Masters" 14 " Married-civ-s…
## 7 49 " Private" 160187 " 9th" 5 " Married-spous…
## 8 52 " Self-emp-not-inc" 209642 " HS-grad" 9 " Married-civ-s…
## 9 31 " Private" 45781 " Masters" 14 " Never-married"
## 10 42 " Private" 159449 " Bachelo… 13 " Married-civ-s…
## # ℹ 32,551 more rows
## # ℹ 9 more variables: Occupation <chr>, Relationship <chr>, Race <chr>,
## # Sex <chr>, Capital_Gain <dbl>, Capital_Loss <dbl>, hrs_week <dbl>,
## # Country <chr>, Annual_pay <chr>
#Set1 Response Variable: Age Explanatory Variables : Final weight and Education Level
class(mydata$Age)
## [1] "numeric"
class(mydata$Fnl_Wgt)
## [1] "numeric"
class(mydata$Education_Level)
## [1] "numeric"
ggplot(data = mydata, aes(x = Age, y = Fnl_Wgt)) +
geom_point() +
labs(x = "Age", y = "Final_Weight") +
ggtitle("Age vs Fnl_Wgt")
The lack of a clear pattern suggests that age and final weight may be
independent of each other. This means that changes in one variable (age)
do not systematically affect changes in the other variable.
#The plot describes the final weight of the adults age
ggplot(data = mydata, aes(x = Age, y = Education_Level)) +
geom_point() +
labs(x = "Age", y = "Education Level") +
ggtitle("Age vs Education Level")
#The plot describes the Education level of adults of various ages
#Correlation between Age and Fnl_Wgt
correlation_Fnl_Wgt <- cor(mydata$Age, mydata$Fnl_Wgt)
# Correlation between Age and Capital_Gain
correlation_EL <- cor(mydata$Age, mydata$Education_Level)
correlation_Fnl_Wgt
## [1] -0.07664587
Since the correlation coefficient is close to zero and negative, it suggests a weak negative linear relationship. The negative sign indicates that as Age increase, the Final Weight tends to decrease slightly, but the relationship is weak. The magnitude of the correlation coefficient being close to zero suggests that the relationship is not strong, meaning that changes in one variable do not consistently predict changes in the other.
correlation_EL
## [1] 0.03652719
The correlation coefficient is close to zero, indicating a very weak linear relationship. The positive sign indicates that as Age variable increases, the other variable Education Level tends to increase slightly, but the relationship is very weak. The magnitude of the correlation coefficient being close to zero suggests that the relationship is almost negligible, meaning that changes in one variable do not consistently predict changes in the other.
confidence_interval_Age <- t.test(mydata$Age)$conf.int
confidence_interval_Age
## [1] 38.43348 38.72981
## attr(,"conf.level")
## [1] 0.95
#Observation for Set1
The correlation between Final weight and Age is negative The correlation between Age and Education Level is Positive 95% of the adults age between 38.4 to 38.7
#Set2 Response Variable : Hours per week Explanatory Variable : Capital Gain and Capital Loss
class(mydata$hrs_week)
## [1] "numeric"
class(mydata$Capital_Gain)
## [1] "numeric"
class(mydata$Capital_Loss)
## [1] "numeric"
ggplot(data = mydata, aes(x = hrs_week, y = Capital_Gain)) +
geom_point() +
labs(x = "hrs_week", y = "Capital_Gain") +
ggtitle("hrs_week vs Capital_Gain")
#The plot describes that the capital gain is less than 25000 for most of
the hours per week
ggplot(data = mydata, aes(x = hrs_week, y = Capital_Loss)) +
geom_point() +
labs(x = "hrs_week", y = "Capital_Loss") +
ggtitle("hrs_week vs Capital_Loss")
#The plot describes the capital loss for various hours per week.
#Correlation between Age and Fnl_Wgt
correlation_CG <- cor(mydata$hrs_week, mydata$Capital_Gain)
# Correlation between Age and Capital_Gain
correlation_CL <- cor(mydata$hrs_week, mydata$Capital_Loss)
correlation_CG
## [1] 0.07840862
correlation_CL
## [1] 0.05425636
confidence_interval_hrs_week <- t.test(mydata$hrs_week)$conf.int
confidence_interval_hrs_week
## [1] 40.30334 40.57158
## attr(,"conf.level")
## [1] 0.95
#Observation for Set2 The correlation between hours per week and capital gain is positive and correlation between hours per week and capital loss is also positive and most(95%) of the hours per week are between 40.30 to 40.50
#Set 3 Response Variable: Education Level Explonatory Variable : Capital Gain and Hours per week
class(mydata$Education_Level)
## [1] "numeric"
class(mydata$Capital_Gain)
## [1] "numeric"
class(mydata$hrs_week)
## [1] "numeric"
ggplot(data = mydata, aes(x = Education_Level, y = Capital_Gain)) +
geom_point() +
labs(x = "Education_Level", y = "Capital_Gain") +
ggtitle("Education_Level vs Capital_Gain")
As the education level increases, there tends to be a corresponding
increase in capital gains. This relationship implies that individuals
with higher education levels may have better job opportunities or
investment strategies, leading to higher capital gains. #The plot
describes the Capital Gain for various Education Levels
ggplot(data = mydata, aes(x = Education_Level, y = hrs_week)) +
geom_point() +
labs(x = "Education_Level", y = "hrs_week") +
ggtitle("Education_Level vs hrs_week")
#The plot describes the hours per week for different education level of
adults
correlation_ELCG <- cor(mydata$Education_Level, mydata$Capital_Gain)
correlation_ELCG
## [1] 0.1226301
there is a slight tendency for individuals with higher education levels to have slightly higher capital gains
correlation_ELHW <- cor(mydata$Education_Level, mydata$hrs_week)
correlation_ELHW
## [1] 0.1481227
there is a slight tendency for individuals with higher education levels to work slightly more hours per week
confidence_interval_Edl <- t.test(mydata$Education_Level)$conf.int
confidence_interval_Edl
## [1] 10.05273 10.10862
## attr(,"conf.level")
## [1] 0.95
the confidence interval suggests that we are 95% confident that the true mean of the Education_Level variable in the population falls between approximately 10.05273 and 10.10862.