RStudio
RStudio
packages("wooldridge")
install.packages("ggplot2")
library(wooldridge)
library(ggplot2)
data(bwght)
#QUESTION 1
# Mean
mean_bwght= mean(bwght$bwght, na.rm=T)
# Median
median_bwght= median(bwght$bwght, na.rm = TRUE)
# Mode (since R does not have a built-in mode function, we'll use a custom function)
getmode= function(v) {
uniqv= unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
mode_bwght=getmode(bwght$bwght)
# Quartiles
quartiles_bwght=quantile(bwght$bwght, probs = c(0.25, 0.5, 0.75), na.rm = TRUE)
# Display results
mean_bwght
median_bwght
mode_bwght
quartiles_bwght
mean_income
sd_income
bwght$log_income=log(bwght$faminc)
smoke_data=bwght[bwght$cigs>1, ]
cor_smoke= cor(smoke_data$bwght, smoke_data$log_income, use = "complete.obs")
non_smoke_data= bwght[bwght$cigs == 0, ]
cor_non_smoke= cor(non_smoke_data$bwght, non_smoke_data$log_income, use =
"complete.obs")
cor_smoke
cor_non_smoke
count_fatheduc= sum(!is.na(bwght$fatheduc))
mean_fatheduc
count_fatheduc
prop_highschool
avg_bwght_highschool
#QUESTION 2
data(meap01)
#1
min_read4=min(meap01$read4, na.rm = TRUE)
max_read4= max(meap01$read4, na.rm = TRUE)
difference_read4= max_read4 - min_read4
min_read4
max_read4
difference_read4
#2
#Number and percentage of schools with a perfect pass rate:
perfect_pass_rate_count
percentage_perfect
pass_rate_50_count
#3
#Compute the average pass rates and visualize:
avg_math4
avg_read4
library(ggplot2)
avg_rates= data.frame(
Subject = c("Math", "Reading"),
Average_Pass_Rate = c(avg_math4, avg_read4)
)
#4 a and b
#Pearson Correlation Coefficient and Scatterplot:
correlation
#5
#Create categories for school size and calculate average pass rates:
#QUESTION 3
data(wage1)
#1
#Calculate the average educational level, lowest, and highest years of education:
avg_education
min_education
max_education
#2
#Determine the average per-hour wage and interpret:
avg_wage
#3
#Calculate the proportion of women and men in the sample:
prop_women
prop_men
#4
#Calculate the probability that a randomly chosen woman is married:
prop_married_women
library(ggplot2)