Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please solve all of question using R code. If not, I can\'t give you full feedba

ID: 2909620 • Letter: P

Question

Please solve all of question using R code. If not, I can't give you full feedback Question 1: Using the SATGPA data set in Stat2Data package. Test by using a 0i l) Create the following three variables and then print out all the six variables a. Create a new vanable "SAT", which is the of MathSAT and VerbatSAT. b. Create second new variable SATLevel", and assign the value of "SATLevel" as I when SAT 1100, 2 when 1100-SAT-1200, 3 when 1200-SAT-1300, and 4 when SAT 1300 GPA -28,2 when 2.8cGPA 3.3,3 when 3.3cGPA their SAT whon GPALevel is the same s Create third new variable "GPALevel" and assign the value of "GPALevel" as 1 when 3.5, and 4 when GPA>3.5 d Print out all the data in the ascending order of their GPALevel and the descending onder of 2) Use the Chi-Square test to conclude if the SATLevel and GPALevel are independent 3) Compute the mean and variance of OPA" for each level of OPALever, and compe correlation matrices for the four variables: MathSAT, VerbalSAT. GPA and SAT 4) Do the data provide safficient evidence to indicate that the mcan of MathSAT is significantly greater 5) Test if the proportion of MathSAT less than VerbalSAT is 05 than the mean of VerbalSAT

Explanation / Answer

## Exporting data files

data("SATGPA",package="Stat2Data")

write.csv(SATGPA, "SATGPA.csv",
quote = FALSE,
row.names = FALSE)


## Importing spreadsheet data (CSV file)
## Save as CSV from Excel first (if needed)

my_data <- read.csv("SATGPA.csv")

## convert character strings to factors?

str(my_data)
SAT<-my_data[1]+my_data[2]
GPA<-my_data[3]

SATLevel<-rnorm(length(SAT[,1]),0,1)
GPALevel<-rnorm(length(GPA[,1]),0,1)

for(i in 1:length(SAT[,1]))
{
if(SAT[i,1]<=1100)
SATLevel[i]<-1
if(SAT[i,1]>1100 && SAT[i,1]<=1200)
SATLevel[i]<-2
if(SAT[i,1]>1200 && SAT[i,1]<=1300)
SATLevel[i]<-3
if(SAT[i,1]>1300)
SATLevel[i]<-4
}
  
for(i in 1:length(GPA[,1]))
{
if(GPA[i,1]<=2.8)
GPALevel[i]<-1
if(GPA[i,1]>2.8 && GPA[i,1]<=3.3)
GPALevel[i]<-2
if(GPA[i,1]>3.3 && GPA[i,1]<=3.5)
GPALevel[i]<-3
if(GPA[i,1]>3.5)
GPALevel[i]<-4

}

# Groupwise Means and variances
d<-cbind.data.frame(GPA,GPALevel)
tapply(d[,1],SATLevel,mean)
tapply(d[,1],SATLevel,var)
colnames(SAT) <- c("SAT")

#Variance -Covariance matrix
var(data.frame(my_data$MathSAT,my_data$VerbalSAT,SAT,GPA))


#For the following tests the null hypothesis will be rejected if the p-value <0.1

#Test for independence
chisq.test(SAT[,1],GPA[,1])

#Test for equality of means
t.test(my_data$MathSAT,my_data$VerbalSAT,alternative = "greater")

#Test for proportions
x<-((my_data$VerbalSAT-my_data$MathSAT)>0)*1
binom.test(sum(x),length(x),p=0.5,alternative = "two.sided")