Вы находитесь на странице: 1из 5

Write a program in R to create two matrices A and B of order 3 X 3 and perform the following

operations:
a. Add matrices A and B
b. Multiply matrices A and B
c. Find the inverse of matrix A
d. Find the inverse of matrix B
e. Find the transpose of matrix B

m1=matrix(c(1,2,3,5,5,6,7,8,9),nrow=3)
print(m1)
m2=matrix(c(1,2,3,6,5,6,7,8,9),nrow=3)
print(m2)
addition=m1+m2
print(addition)

multiplication=m1%*%m2
print(multiplication)

solve(m1)
solve(m2)

t1=t(m1)
print(t1)
t2=t(m2)
print(t2)

A random sample of 33 individuals who listen to talk radio was selected and the hours per week
that each listens to talk radio was determined. The data are as follows.
9 8 7 4 8 6 8 8 7 10 8 10 6 7 7 8 9 6 5 8 5 6 8 7
8 5 5 8 7 6 6 4 5
Test the null hypothesis using R that µ = 5 hours (h) versus the alternative hypothesis that µ ≠ 5 at
level of significance α = 0.05 in the following three equivalent ways: (a) Compute the value of the
test statistic and compare it with the critical value for α = 0.05 (b) Compute the p-value
corresponding to the computed test statistic and compare the p-value with α = 0.05. (c) Compute
the 1 - α = 0.95 confidence interval for µ and determine whether 5 falls in this interval
X=c(9,8,7,4,8,6,8,8,7,10,8,10,6,7,7,8,9,6,5,8,5,6,8,7,8,5,5,8,7,6,6,4,5)
xbar=mean(X)
print(xbar)
sigma=sd(X)
print(sigma)
n=33
mu0=5
z=(xbar-mu0)/(sigma/sqrt(n))
z
alpha=0.05
z.half.alpha=qnorm(1-alpha/2)
c(-z.half.alpha,z.half.alpha)
A car travels 25 miles at 25 miles per hour (mi/h), 25 miles at 50 mph, and 25 miles at 75 mph.
Write a program to find the arithmetic mean of the three velocities and the harmonic mean of the
three velocities. Which is correct?
f=c(25,50,75)
x=c(25,25,25)
fx=f*x
colnames=c("x","f","fx")
rownames=c("1","2","3","Total")
data=c(x,sum(x),f,sum(f),fx=sum(fx))
y=matrix(data,nrow=length(x)+1,dimnames=list(rownames,colnames))
print(y)
am=sum(fx)/sum(f)
print(am)
hm=sum(f)/6
print(hm)
2(2):Enter the following details of wages of 65 employees at the ABC Ltd. In Excel:
data=read.csv("data3.csv")
print(data)
cf=cumsum(data$NoE)

colnames=c("freq(f)","cf")
rownames=c("24999.5-25999.5","25999.5-26999.5","26999.5-27999.5","27999.5-
28999.5","28999.5-29999.5","29999.5-30999.5","30999.5-31999.5")
data=c(data$NoE,cf)
y=matrix(data,nrow=length(cf),dimnames=list(rownames,colnames))
print(y)

#median
N=65
N/2
F=16;C=18;L=26999.5;h=27999.5-26999.5
M=L+(N/2-C)/F*h
cat("median=",M)

#mode
fm=16;f1=10;f2=14;
mode=L+((fm-f1)/(2*fm-f1-f2))*h
cat("mode=",mode)

Enter the following data sets in Excel:


a) 12, 6, 7, 3, 15, 10, 18, 5
b) 9, 3, 8, 8, 9, 8, 9, 18.
Import the data in R and find standard deviation and variance of the data sets using R.
data=read.csv("data5.csv")
data1=read.csv("data6.csv")
print(data)
sd1=sd(data$x)
print(sd1)
var1=var(data$x)
print(var1)
sd2=sd(data1$x)
print(sd2)
var2=var(data1$x)
print(var2)

5(1):Enter the following details of wages of 65 employees at the ABC Ltd. In Excel:
data=read.csv("data3.csv")
print(data)

x=seq(25499.5,31499.5,999)
x1=data$NoE
f=data$NoE
fx=f*x
colnames=c("x","f","fx")
rownames=c("25000-25999","26000-26999","27000-27999","28000-28999","29000-29999","30000-
30999","31000-31999","Total")
data=c(x,sum(x),f,sum(f),fx,sum(fx))
y=matrix(data,nrow=length(x)+1,dimnames=list(rownames,colnames))
print(y)

mean=sum(fx)/sum(f)
print(mean)

sd1=sd(x1)
print(sd1)

var1=var(x1)
print(var1)

#mode
fm=16;f1=10;f2=14;L=26999.5;h=27999.5-26999.5
mode=L+((fm-f1)/(2*fm-f1-f2))*h
cat("mode=",mode)

5(2)Enter the following table which shows the heights(H) to the nearest inch (in) and the
weights(W) to the nearest pound (lb) of a sample of 12 male students drawn at random from the
first-year students at College.
data=read.csv("data4.csv")
print(data)

print("H as independent:")
fit=lm(data$W~data$H)
print(fit)
cat("W=",-60.746,"+",3.216,"H")
print("H as independent:")
fit1=lm(data$H~data$W)
print(fit1)
cat("H=",31.1078,"+",0.2371,"W")

6(1)Enter the total agricultural exports in millions of dollars in Excel:


data=read.csv("data2.csv")
print(data)
x=data$Year
y=data$Value
relation=lm(y~x)
a=(data.frame(x=2006))
result=predict(relation,a)
print(result)
plot(x,y,main=" total agricultural exports in millions of dollars")
plot(x,y,main=" total agricultural exports in millions of dollars",abline(lm(y~x)))

6(2)Many casinos use card-dealing machines to deal cards at random. Occasionally, the machine is
tested to ensure an equal likelihood of dealing for each suit. To conduct the test, 1,500 cards are
dealt from the machine, while the number of cards in each suit is counted. Theoretically, 375 cards
should be dealt from each suit. But this is not the case as shown in the following table:
data=read.csv("data8.csv")
print(data)
print(chisq.test(data))

7(2)A business owner had been working to improve employee relations in his company. He
predicted that he met his goal of increasing employee satisfaction from 65% to 80%. Employees
from four departments were asked if they were satisfied with the working conditions of the
company. The results are shown in the following table:
data=read.csv("data1.csv")
print(data)
print(chisq.test(data))

8(1)Enter the following table in Excel which shows the first two grades (denoted by First Quiz X
and Second Quiz Y, respectively) of 10 students on two short quizzes in biology.
data=read.csv("data.csv")
print(data)

print("Y on X:")
fit=lm(data$Y~data$X)
print(fit)
cat("y=",5.8667,"+",0.2333,"x")

print("X on Y:")
fit1=lm(data$X~data$Y)
print(fit1)
cat("x=",4.8571,"+",0.2875,"y")

Вам также может понравиться