list_1<-c(1,2,1,3,4,1,1,4,2,1,3,4,3,2,1,3,4,1,2,3,1,1,2,1,1,3,4)
class(list_1)
## [1] "numeric"
# Convert to character labels
list_1_factor <- factor(list_1, levels = 1:4, labels = c("Freshman", "Sophomore", "Junior", "Senior"))
list_1_character <- as.character(list_1_factor)
class(list_1_character)
## [1] "character"
print(list_1_character)
## [1] "Freshman" "Sophomore" "Freshman" "Junior" "Senior" "Freshman"
## [7] "Freshman" "Senior" "Sophomore" "Freshman" "Junior" "Senior"
## [13] "Junior" "Sophomore" "Freshman" "Junior" "Senior" "Freshman"
## [19] "Sophomore" "Junior" "Freshman" "Freshman" "Sophomore" "Freshman"
## [25] "Freshman" "Junior" "Senior"
By converting the list into characters, it created a list of 27 values where 1 represents freshman, 2 represents sophomore, 3 represents junior and 4 represents senior.
list_IQ<-c(105,69,86,100,82,111,104,110,87,108,87,90,94,113,112,98,80,97,95,111,114,89,95,126,98)
#construcing 90% confidence interval
xbar<-mean(list_IQ)
s<-sd(list_IQ)
n = length(list_IQ)
alpha<-0.1
criticalt<-qt(0.05,n-1,lower.tail = F)
#FINDING 90% INTERVAL
L<-xbar-criticalt*s/sqrt(n)
U<-xbar+criticalt*s/sqrt(n)
L <- round(L, digits = 2)
U<-round(U, digits = 2)
#Printing 90% interval
confidence_interval_west = paste("(",L,",",U, ")")
print(confidence_interval_west)
## [1] "( 93.96 , 102.92 )"
Assuming the population of the sample selected is normally distributed, there is a 90% probability that the population IQ lies within the interval of 93.96 and 102.92.
list_IQ_2<-c(105,69,86,100,82,111,104,110,87,108,87,90,94,113,112,98,80,97,95,111,114,89,95,126,98)
standard_dev_listIQ = sd(list_IQ_2)
# T Test -> mu is pop mean
t.test(list_IQ_2, mu = 100, alternative = "greater",conf.level = 0.95)
##
## One Sample t-test
##
## data: list_IQ_2
## t = -0.59574, df = 24, p-value = 0.7215
## alternative hypothesis: true mean is greater than 100
## 95 percent confidence interval:
## 93.95993 Inf
## sample estimates:
## mean of x
## 98.44
The mean IQ in the counselor’s class (M = 98.44, SD = 13.09) was not significantly different than in the average IQ in the population, t(24) = -0.6, p = 0.7215.
#downloading dataset
expenditure<-read.table("~/Desktop/QTM 200/HW_1/expenditure.txt",header=T)
#creating scatterplott matrix
selected_vars <- expenditure[, c("Y", "X1", "X2", "X3")]
new_var_names <- c("expenditure", "personal income", "residents under 18", "urban areas")
colnames(selected_vars) <- new_var_names
pairs(selected_vars)
I decided to produce a scatterplot matrix, which are multivariate scatterplot that show the relationship across multiple quantitative variables.
It is important to note that the qualitative variables represent the following: expenditure represents the per capita expenditure on public education personal income represents the per capita personal income residents under 18 represents the number of residents per thousand under 18 years of age urban areas represents the number of people per thousand residing in urban areas
Looking at the graph expenditure seems to have a positive linear relationship with both the variables personal income and residents under 18 and no linear relationship with the variable urban areas
On the other hand personal income seems to have a negative linear relationship with residents under 18 and a positive linear relationship with urban areas.
Finally residents under 18 appears to have a negative linear relationship with urban areas.
#making regions into factor
expenditure$Region <- factor(expenditure$Region, levels = 1:4, labels = c("Northeast", "North Central", "South", "West"))
#creating box plot
boxplot(Y ~ Region, data = expenditure, ylab = "per capita expenditure on public education", xlab = "region")
#analysis of West
expenditure<-read.table("~/Desktop/QTM 200/HW_1/expenditure.txt",header=T)
filtered_data_west <- expenditure %>%
filter(Region == 4)
#confidence interval
xbar<-mean(filtered_data_west$Y)
s<-sd(filtered_data_west$Y)
n<-nrow(filtered_data_west)
alpha<-0.05
criticalt<-qt(0.025,n-1,lower.tail = F)
L<-xbar-criticalt*s/sqrt(n)
U<-xbar+criticalt*s/sqrt(n)
L <- round(L, digits = 2)
U<-round(U, digits = 2)
confidence_interval_west = paste("(",L,",",U, ")")
print(confidence_interval_west)
## [1] "( 95.28 , 116.72 )"
I utilized a boxplot to understand the relationship between the categorical variable region, and the numerical variable y (which represents per capita expenditure on public education). After creating the graph, I realized that the region West had the highest mean of y, which is why a further analysis into this Region was done. After calculating a 95% confidence interval, it can be said that there is a 95% probability that true average per capita expenditure on public education in the West lies within the interval of 95.28 to 116.72.
#plot expenditure by personal income
plot(expenditure$X1, expenditure$Y,
xlab = "per capita personal income",
ylab = "per capita expenditure on public education")
expenditure$Region <- factor(expenditure$Region, levels = 1:4, labels = c("Northeast", "North Central", "South", "West"))
#plot adding region region
plot(expenditure$X1, expenditure$Y,
col = ifelse(expenditure$Region == "Northeast", "blue",
ifelse(expenditure$Region == "North Central","red",
ifelse(expenditure$Region == "South", "purple", "green"))),
pch = ifelse(expenditure$Region == "Northeast", 1,
ifelse(expenditure$Region == "North Central", 2,
ifelse(expenditure$Region == "South", 3, 4))),
xlab = "per capita personal income",
ylab = "per capita expenditure on public education")
legend("topleft", c("Northeast", "North Central", "South", "West"),
pch = c(1, 2, 3, 4),
col = c("blue", "red", "purple", "green"))
There seems to be a positive linear relationship between per capita personal income and per capita expenditure on public education. Additionally, this connection seems to remain true across regions, with the North Central region appearing to have the weakest positive linear relationship.