NRG 2

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#-----------------------------------------------------

setwd("C:\\Users\\GIM\\Desktop\\anirudh")
Bottles <- read.csv("bottles.csv")
VolumeMean <- mean(Bottles$Volume)
VolumeStdDev <- sd(Bottles$Volume)
pnorm1 <-pnorm(480,VolumeMean,VolumeStdDev)
pnorm2 <-pnorm(520,VolumeMean,VolumeStdDev)
pnorm1.1 <- pnorm2-pnorm1
#-----------------------------------------------------
setwd("C:\\Users\\GIM\\Desktop\\anirudh")
Census <- read.csv("Census.csv")
library(dplyr)
q2.1 <-
select(Census,State,Males,Females,Persons..literate,Males..Literate,Females..Litera
te)
q2.2 <- group_by(q2.1,State)
q2.3 <- summarise(q2.2,a=sum(Males),b=sum(Females))
View(q2.3)
q2.4 <- filter(q2.3,b<a)
View(q2.4)
totalpopulation<- q2.1$Males +q2.2$Females
q2.5 <- mutate(q2.4,totalpopulation)
#-------------------------------------------------------
q3.1 <- ppois(6,7,lower.tail = TRUE)
q3.2 <- 1-ppois(10,7,lower.tail = TRUE)
#-------------------------------------------------------
x<-pnorm(172,160,30/sqrt(36))
y<- 2*(1-x)
#-------------------------------------------------------
library(BSDA)
iqs <- c(122,125,130,110,140)
z.test(iqs,mu=100,sigma.x=16,alternative="two.sided",conf.level=0.95)

mercury_level <-c(67,46,48,61,65,68,66,57,48,51)
t.test(mercury_level,mu=50,alternative="greater",conf.level=0.99)

pnorm(1.96,0,1)
qnorm(0.976,0,1)
x <-rnorm(10000,0,1)
mean(x)
sd(x)

n <- 100
pnorm(80,0.5,sqrt(0.25/100))

#----------------------------------------------------
setwd("C:\\Users\\GIM\\Desktop\\anirudh")
Poison <- read.csv("Poison.csv")
View(Poison)
p1<- c(rep("A",8),rep("B",8),rep("C",8))
p2<- c(rep(1,8),rep(2,8),rep(3,8))
df<- data.frame(p1,p2)
desc(Poison)
a1<-levels(Poison$poison)
group_by(Poison,poison)
summarise(
count_poison = n(),
mean_time = mean(time, na.rm = TRUE),
sd_time = sd(time, na.rm = TRUE)
)
#--------------------------------------------------anova
x<-read.csv("1wayparachutedata.csv")
library(tidyr)
supplier<-
c(rep("supplier.1",5),rep("supplier.2",5),rep("supplier.3",5),rep("supplier.4",5))
strength <-c(x$Supplier.1,x$Supplier.2,x$Supplier.3,x$Supplier.4)
df<- data.frame(supplier,strength)
parachute1way<-gather(x,key = Supplier, value = Strength)
boxplot(Strength ~ Supplier, parachute1way)
oneway.test(Strength ~ Supplier, parachute1way, var.equal = TRUE)
summary(aov(Strength ~ Supplier, parachute1way))
#--------------------------------------------------
# t-test - carpet sales
setwd("C:\\Users\\Amit Ram\\Documents\\BDA Docs\\GIM teaching\\PWR\\Lab8")
carpet_sales <- read.csv("carpet_sales.csv", header = TRUE)
t.test(carpet_sales[[1]], carpet_sales[[2]],conf.level = 0.95, var.equal =TRUE)

#t-test (one sided) - mercury levels safe


mercury_levels<-c(67, 46, 48, 61, 65, 68, 66, 57, 48, 51)
t.test(mercury_levels,conf.level=0.95, mu=50, alternative = "greater")

#paired t-test: Is Amazon cheaper


diff_prices <- c(-5.74, -0.78, -0.94, 15.36, 0.64, 14.79, 0.77, 2.52, 5.94, 5.24,
-23.77, -18.5, 4.87, 11.06)
t.test(diff_prices,conf.level = 0.95)

#z-test for IQs - cheating in an IQ test


library(BSDA)
z.test(IQs, mu=100, sigma.x = 16, alternative ="two.sided", conf.level = 0.95)

#z-test for large samples - variance not equal


bedsheet_sales <- read.csv("bed-sheet-sales.csv",header = TRUE)
z.test(bedsheet_sales[[1]],bedsheet_sales[[2]],alternative ="two.sided", conf.level
=0.95, sigma.x = sd(bedsheet_sales[[1]]), sigma.y=sd(bedsheet_sales[[2]]))

#z test of proportions for fast food chain


z_s <- (0.94-0.85)/sqrt(0.85*(1-0.85)/100)
print(paste("p-value =",1-pnorm(z_s,0,1)))
print(paste("z statistic= ",z_s," and z_crit=", qnorm(0.975,0,1)))

#F-test for variances for accounting students


F_s=210.2/36.5
print(paste("F =",F_s ," p value =",1-pf(F_s,12,9)))
print(paste("F = ",F_s," F_crit = ",qf(0.95,12,9) ))

#F-test to compare variances


var.test(money_market,CD, ratio =1)

setwd("C:\\datasets")
deathrate = read.csv("death_rate.csv", header = TRUE)
lm.fit <- lm(Log.Probability ~ Age, deathrate)
summary(lm.fit)
'
lm(formula = Log.Probability ~ Age, data = deathrate)

You might also like