Title :“Phase 1” Author:“Muhammad Bilal” Date: “18-11-2023”

#assignment Phase 1

CamPriceData <- read.csv("D:/Sem 3/SI/data set  prices of nikon and canon cameras updated.csv")

#attach the data
attach(CamPriceData)

#summary of the data
summary(CamPriceData)
##   Observation       Brand              Price_.        Megapixels   
##  Min.   : 1.00   Length:28          Min.   : 72.0   Min.   :10.00  
##  1st Qu.: 7.75   Class :character   1st Qu.: 99.0   1st Qu.:12.00  
##  Median :14.50   Mode  :character   Median :144.0   Median :12.00  
##  Mean   :14.50                      Mean   :157.8   Mean   :12.86  
##  3rd Qu.:21.25                      3rd Qu.:180.0   3rd Qu.:14.00  
##  Max.   :28.00                      Max.   :360.0   Max.   :16.00  
##    Weight_oz         Score          Brand.1      
##  Min.   :4.000   Min.   :51.00   Min.   :0.0000  
##  1st Qu.:5.000   1st Qu.:61.00   1st Qu.:0.0000  
##  Median :6.000   Median :65.50   Median :0.0000  
##  Mean   :5.821   Mean   :65.36   Mean   :0.4643  
##  3rd Qu.:7.000   3rd Qu.:70.25   3rd Qu.:1.0000  
##  Max.   :7.000   Max.   :75.00   Max.   :1.0000

##DAta types: Brand: string Price_.: integer Megapixels: integer weight_oz: integer score: Integer Brand.1: Boolean

##Measurement scale: Brand:nominal Price_.: scaled Megapixels: scaled weight_oz: scaled score: scaled Brand.1: normal

#subsets for nikon and canon cameras

NikonPrice <- CamPriceData$Price_.[CamPriceData$Brand=="Nikon"]
CanonPrice <- CamPriceData$Price_.[CamPriceData$Brand=="Canon"]

str(CamPriceData)
## 'data.frame':    28 obs. of  7 variables:
##  $ Observation: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Brand      : chr  "Canon" "Canon" "Canon" "Canon" ...
##  $ Price_.    : int  297 180 270 180 162 180 180 117 117 99 ...
##  $ Megapixels : int  10 12 12 10 12 12 14 10 12 16 ...
##  $ Weight_oz  : int  7 5 7 6 5 7 5 7 5 5 ...
##  $ Score      : int  75 75 74 71 71 70 69 69 68 64 ...
##  $ Brand.1    : int  1 1 1 1 1 1 1 1 1 1 ...

#Checking normality using histogram

#histogram for Nikon camera

hist(NikonPrice, main = "Nikon Camera Prices")

#histogram for Canon Camera

hist(CanonPrice,main = "Canon Camera Prices")

#checking normality using QQ plot #qq plot for Nikon

qqnorm(NikonPrice, main="Normal")

#qq plot for canon
qqnorm(CanonPrice, main="Normal")

#data seems normal
summary(NikonPrice)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    72.0   103.5   135.0   159.0   193.5   360.0
summary(CanonPrice)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    81.0    99.0   162.0   156.5   180.0   297.0

#Testing Hypothesis # H0: Nikonprice is equal to Canonprice # H1: Nikonprice is not equal to Canonprice

#performing t test

t.test(NikonPrice,CanonPrice)
## 
##  Welch Two Sample t-test
## 
## data:  NikonPrice and CanonPrice
## t = 0.08931, df = 25.993, p-value = 0.9295
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -55.88673  60.96365
## sample estimates:
## mean of x mean of y 
##  159.0000  156.4615

#data shows sufficient evidence to conclude that H0 is true. #accept the null hypothesis

#new variable ‘xweight’ from the data of ‘weight_oz’ data

CamPriceData$xweight <- ifelse(CamPriceData$Weight_oz %in% c(4,5), "light weight", ifelse(CamPriceData$Weight_oz ==6, "medium weight", ifelse(CamPriceData$Weight_oz==7, "heavy weight", NA)))

Performing anova test

Ho: Avg price of light weight=Avg price of medium weight=Avg price of heavy weight

H1: Atleast 2 are unequal

AnovaResult <- aov(Price_.~xweight, data=CamPriceData)
summary(AnovaResult)
##             Df Sum Sq Mean Sq F value Pr(>F)
## xweight      2  16610    8305   1.557   0.23
## Residuals   25 133318    5333

#pvalue of 0.23 is greater than significant value #there isnt sufficient evidence to reject null hypothesis #hence the avg price of all weight category cameras is same