You are on page 1of 2

Fuction for Z test

Z.test<-function(X_bar,mu,n,CI, sigma){
Z= (X_bar-mu)/sigma*sqrt(n)
print(Z)
alpha=(100-CI)/100
UCV = qnorm(1-alpha/2)
LCV = UCV*(-1)
if(Z>UCV || Z<LCV)
print("Rejcet the null hypothesis")
else
print("Fail to reject the hypothesis")
}

Function for T test

T.test<-function(X_bar,mu,n,alpha,s){
t=(X_bar-mu)/s*sqrt(n)
UCV=qt(1-alpha/2, n-1)
LCV =UCV*(-1)
if(t > UCV || t< LCV)
print("Reject")
else
print("Fail to reject")
print(t)
}

ANOVA

> X<-
c(3.45,3.63,3.89,4,3.35,3.5,3.75,3.13,3.28,2.8,3.31,2.79,3.38,3.45,3.25,3.15,3,3.7,
3,2.8,2.65,2.75,3.25,3.50)
> split_X<-c(rep("CS245", 7),rep("CS116",5),rep("CS216",6),rep("MATH120",6))
> model=data.frame(X,split_X)
> results=aov(X~split_X, data=model)
> summary(results)

Liner Regression

> X<-c(0,1.5,2,2.8,3.5)
> Y<-c(0,1.7,2.1,2.5,3.0)
> liner.model=lm(Y~X)
> summary(liner.model)

Call:
lm(formula = Y ~ X)

Residuals:
1 2 3 4 5
-0.20505 0.22841 0.20623 -0.06927 -0.16032

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.20505 b0 0.20292 1.01 0.38670
X 0.84436 b1 0.08841 9.55 0.00244 ** Reject the H0
because alpha is greater than p value.
--- p-value
Signif. codes: 0 �***� 0.001 �**� 0.01 �*� 0.05 �.� 0.1 � � 1
Residual standard error: 0.2361 on 3 degrees of freedom
Multiple R-squared: 0.9682, Adjusted R-squared: 0.9575
F-statistic: 91.21 on 1 and 3 DF, p-value: 0.002435

You might also like