R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

#====================Question#2====================
ov<-matrix(c(120,110,90,95,40,45),nrow=2)
row.names(ov)<-c('Male','Female')
colnames(ov)<-c('Republic','Democrate','Independent')
ct<-ov
ct
##        Republic Democrate Independent
## Male        120        90          40
## Female      110        95          45
row_total<-rowSums(ct)
col_total<-colSums(ct)
total<-sum(ov)
ev<-outer(row_total,col_total,'*')/total
chi_sq<-sum( ( (ov-ev)^2)/ev)
chi_sq
## [1] 0.8640354
chisq.test(ct)
## 
##  Pearson's Chi-squared test
## 
## data:  ct
## X-squared = 0.86404, df = 2, p-value = 0.6492
#Critical regio:
df<-(nrow(ov)-1)*(ncol(ov)-1)
qchisq(1-0.05,df)
## [1] 5.991465
#========================Question3==================================
s1<-c(52,46,62,48,57,54)
s2<-c(66,49,64,53,68)
s3<-c(63,65,58,70,71,73)

column1<-c(s1,s2,s3)
p1<-rep('Student1',6)
p1
## [1] "Student1" "Student1" "Student1" "Student1" "Student1" "Student1"
p2<-rep('Student2',5)
p1
## [1] "Student1" "Student1" "Student1" "Student1" "Student1" "Student1"
p3<-rep('Student3',6)
p1
## [1] "Student1" "Student1" "Student1" "Student1" "Student1" "Student1"
column2<-c(p1,p2,p3)
df<-data.frame(students=column2,marks=column1)
df
##    students marks
## 1  Student1    52
## 2  Student1    46
## 3  Student1    62
## 4  Student1    48
## 5  Student1    57
## 6  Student1    54
## 7  Student2    66
## 8  Student2    49
## 9  Student2    64
## 10 Student2    53
## 11 Student2    68
## 12 Student3    63
## 13 Student3    65
## 14 Student3    58
## 15 Student3    70
## 16 Student3    71
## 17 Student3    73
#normality check
result<-aov(marks~students,data=df)
result
## Call:
##    aov(formula = marks ~ students, data = df)
## 
## Terms:
##                 students Residuals
## Sum of Squares  546.7745  620.1667
## Deg. of Freedom        2        14
## 
## Residual standard error: 6.655646
## Estimated effects may be unbalanced
Residual<-residuals(result)
Residual
##           1           2           3           4           5           6 
##  -1.1666667  -7.1666667   8.8333333  -5.1666667   3.8333333   0.8333333 
##           7           8           9          10          11          12 
##   6.0000000 -11.0000000   4.0000000  -7.0000000   8.0000000  -3.6666667 
##          13          14          15          16          17 
##  -1.6666667  -8.6666667   3.3333333   4.3333333   6.3333333
shapiro.test(Residual)
## 
##  Shapiro-Wilk normality test
## 
## data:  Residual
## W = 0.94271, p-value = 0.3517
#Kruskall_wallis
kruskal.test(marks~students,data=df)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  marks by students
## Kruskal-Wallis chi-squared = 7.8575, df = 2, p-value = 0.01967
#Variance test :

library(car)
## Warning: package 'car' was built under R version 4.3.2
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.3.2
leveneTest(marks~students,data=df)
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  2  0.3318 0.7232
##       14
#========================================================
#  mean
sample<-c(5260,5470,5640,6180,6390,6515,6805,7515,7515,8230,8770)
mean(sample)
## [1] 6753.636
mean<-sum(sample)/length(sample)
mean
## [1] 6753.636
#var
variance<-var(sample)
variance
## [1] 1304445
#sd
sd(sample)
## [1] 1142.123
#variance
var<-(1/(length(sample)-1))*( sum((sample)^2)-((sum(sample)^2)/length(sample)))
var
## [1] 1304445
standard_daviation<-sqrt(var)
standard_daviation
## [1] 1142.123
#Box_plot:
plot<-boxplot(sample)

summary(sample)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    5260    5910    6515    6754    7515    8770
#Test_statsistics:

shapiro.test(sample)
## 
##  Shapiro-Wilk normality test
## 
## data:  sample
## W = 0.95237, p-value = 0.6743
t.test(sample,alternative='two.sided',mu=7725)
## 
##  One Sample t-test
## 
## data:  sample
## t = -2.8208, df = 10, p-value = 0.01814
## alternative hypothesis: true mean is not equal to 7725
## 95 percent confidence interval:
##  5986.348 7520.925
## sample estimates:
## mean of x 
##  6753.636
#using formulae
t<-(mean(sample)-7725)/(sd(sample)/sqrt(length(sample)))
t
## [1] -2.820754
n<-length(sample)
qt(0.05/2,n-1)
## [1] -2.228139