Posts

LAB MANUAL PDF

   R LAB Pdf

Hypothesis testing using R Experiment :3 Small-Sample Single mean . Experiment :4 Chi-squared test

  #LAB-10 #Hypothesis Testing Using R #Program-1 x=c( 5 , 2 , 8 ,- 1 , 3 , 0 ,- 2 , 1 , 5 , 0 , 4 , 6 ) xbar=mean(x) s=sd(x) n= 12 mu= 0 t=(xbar-mu)/(s/sqrt(n)) cat( "Test statistic=" ,t) alpha= 0.05 t.alpha=qt( 1 -alpha/ 2 ,df=n- 1 ) cat( "t-Table value:" ,t.alpha) #Program-2 xbar= 9900 mu= 10000 n= 25 s= 125 t=(xbar-mu)/(s/sqrt(n)) cat( "Test statistic=" ,t) alpha= 0.05 t.alpha=qt( 1 -alpha,df=n- 1 ) cat( "t-Table value:" ,-t.alpha) #Program-3 xbar= 2.1 s= 0.3 n= 28 mu= 2 t=(xbar-mu)/(s/sqrt(n)) cat( "Test statistic=" ,t) alpha= 0.05 t.alpha=qt( 1 -alpha/ 2 ,df=n- 1 ) cat( "t-Table value:" ,t.alpha) #Chi-Square test for Independence #Program-1 x=matrix(c( 24 , 289 , 9 , 100 , 13 , 565 ),nrow= 2 ) View(x) chisq.test(x) qchisq(p= 0.05 ,df= 2 ,lower.tail= FALSE ) #Program-2 x=matrix(c( 100 , 20 , 150 , 30 , 20 , 180 ),nrow= 2 ) View(x) chisq.test(x) qchisq(p= 0.05 ,df= 2 ,lower.tail= FALSE ) #Student Task xbar= 990 mu= 1000 n= ...

Hypothesis testing using R Experiment :1 Large-Sample Single mean Experiment :2 Large-Sample Single proportion.

  #LAB 9 #Program 1 n = 30 xbar = 788 mu = 800 sigma = 40   z = (xbar-mu)/(sigma/sqrt(n)) cat( "Test statistic =" ,z) alpha = .05 z.alpha = qnorm( 1 -alpha/ 2 ) cat( "Z- Table value :" ,-z.alpha) #Program 2 n = 100 xbar = 71.8 mu = 70 sigma = 8.9 z = (xbar-mu)/(sigma/sqrt(n)) cat( "Test statistic =" ,z) alpha = .05 z.alpha = qnorm( 1 -alpha) cat( "Z- Table value :" ,z.alpha) #Program 3 n = 36 xbar = 28.5 mu = 30 sigma = 3.5 z = (xbar-mu)/(sigma/sqrt(n)) cat( "Test statistic =" ,z) alpha = .01 z.alpha = qnorm( 1 -alpha) cat( "Z- Table value :" ,-z.alpha) #Single Propotion #Program 1 p = 85 / 148 P = .6 n = 148 z = (p-P)/sqrt(P*( 1 -P)/n) cat( "Test statistic =" ,z) alpha = .05 z.alpha = qnorm( 1 -alpha) cat( "Z- Table value :" ,z.alpha) #Program 2 p = 30 / 214 P = .12 n = 214 z = (p-P)/sqrt(P*( 1 -P)/n) cat( "Test statistic =" ,z) alpha = .05 z.alpha = qnorm( 1 -alpha) cat( "Z-...

Probability distributions using R Experiment :1 Binomial Distribution Experiment :2 Poisson Distribution Experiment :3 Normal Distribution

  #Lab-8 #Program 1 Probability distribution b1=pbinom( 4 , 12 , 0.2 )   #n=12 p=0.2 b2=dbinom( 3 , 12 , 0.2 ) b3=sum(dbinom( 2 : 4 , 12 , 0.2 )) b4=rbinom( 3 , 12 , 0.2 ) b5= 1 -pbinom( 3 , 12 , 0.2 ) b6= 1 -pbinom( 5 , 12 , 0.2 ) b7=sum(dbinom( 0 : 6 , 12 , 0.2 )) b1 b2 b3 b4 b5 b6 b7 #Program 2 #n=6 #p=0.5 b1=dbinom( 2 , 6 , 0.5 ) b2= 1 -pbinom( 4 , 6 , 0.5 ) b3= 1 -pbinom( 0 , 6 , 0.5 ) b1 b2 b3 #Poisson Distribution #Program 1 n= 2000 p= 0.001 dpois( 3 ,lambda=n*p) ppois( 2 ,lambda=n*p,lower= FALSE ) #Program 2 ppois( 17 ,lambda = 12 ) #Left Tailed #Other Program ppois( 17 ,lambda = 12 ,lower= FALSE ) #Right Tailed #Program 3 ppois( 2 ,lambda = 4 ) #Left Tailed dpois( 3 ,lambda= 4 ) #Normal Distribution #dnorm Ex-1 dnorm( 0 ,mean= 0 ,sd= 1 ) #Ex-2 z_scores=seq(- 3 , 3 ,by= 0.1 ) dvalues=dnorm(z_scores) dvalues #pnorm EX-1 pnorm( 0 ) #EX-2 pnorm( 2 ,mean = 5 ,sd= 3 ,lower.tail = F) #EX-3 1 -pnorm( 2 ,mean = 5 ,sd= 3 ,lower.tail = FALSE ) #qnorm #EX-1 qnorm( 0.5 ) #EX-2 qno...

Lines of Regression, Angle between two lines of regression and estimated values of variables. Experiment :1 Finding (a) Regression line of y on x and (b) Regression line of x on y. Experiment :2 Predicting y value for a given x. Experiment :3 Angle between two lines of regression

  #Lines of Regression a) x=c( 14 , 19 , 24 , 21 , 26 , 22 , 15 , 20 , 19 ) y=c( 31 , 36 , 48 , 37 , 50 , 45 , 33 , 41 , 39 ) relation=lm(y ~ x) print(relation) #Lines of Regression 2 x=c( 14 , 19 , 24 , 21 , 26 , 22 , 15 , 20 , 19 ) y=c( 31 , 36 , 48 , 37 , 50 , 45 , 33 , 41 , 39 ) relation1=lm(x ~ y) print(relation1) #2)Prediction y values for x x =c( 151 , 174 , 138 , 186 , 128 , 136 , 179 , 163 , 152 , 131 ) y =c( 63 , 81 , 56 , 91 , 47 , 57 , 76 , 72 , 62 , 48 ) relation= lm(y ~ x) a = data.frame(x= 170 ) result = predict(relation,a) print(result) #3) Angle Between Two Lines of regression x=c( 14 , 19 , 24 , 21 , 26 , 22 , 15 , 20 , 19 ) y=c( 31 , 36 , 48 , 37 , 50 , 45 , 33 , 41 , 39 ) r1=lm(y ~ x) r2=lm(x ~ y) m1=r1 $ coeff[ 2 ] m2= 1 /r2 $ coeff[ 2 ] angle=atan((m2-m1)/( 1 +m1*m2))* 180 /pi abs(angle) #Student Task 1 x=c( 1 , 3 , 4 , 6 , 8 , 9 , 11 , 14 ) y=c( 1 , 2 , 4 , 4 , 5 , 7 , 8 , 9 ) print(lm(y ~ x)) print(lm(x ~ y)) #Predict() x =c( 12 , 14 , 32 , 65 , 21 ) y =c( 2...

Coefficient of correlation Experiment :1 Finding the Correlation Coefficient to the given data Experiment :2 Finding the Correlation Coefficient to the data from an excel file. Experiment :3 Finding the Correlation Coefficient to the data from builtin data base. Experiment :4 Rank Correlation.

  #LAB-6 #Scatter diagram x=c( 50 , 50 , 55 , 60 , 65 , 65 , 65 , 60 , 60 , 50 ) y=c( 11 , 13 , 14 , 16 , 16 , 15 , 15 , 14 , 13 , 13 ) plot(x,y,main= "scatter plot" ,xlab= "Sales" ,ylab= "Expenses" ) scatter.smooth(x,y,main= "scatter plot" ,xlab= "Sales" ,ylab= "Expenses" ) #Corelation Coeffient x=c( 50 , 50 , 55 , 60 , 65 , 65 , 65 , 60 , 60 , 50 ) y=c( 11 , 13 , 14 , 16 , 16 , 15 , 15 , 14 , 13 , 13 ) result=cor(x,y,method= "pearson" ) cat( "Pearson correlation coeffient is:" ,result) #Covariance x=c( 50 , 50 , 55 , 60 , 65 , 65 , 65 , 60 , 60 , 50 ) y=c( 11 , 13 , 14 , 16 , 16 , 15 , 15 , 14 , 13 , 13 ) print(cov(x,y,method= "spearman" )) #Program 2 #Corelation Coeffient by pearson x=c( 1 , 2 , 3 , 4 , 5 , 6 , 7 ) y=c( 1 , 3 , 6 , 2 , 7 , 4 , 5 ) result=cor(x,y,method= "pearson" ) cat( "Pearson correlation coefficient is:" ,result) #Corelation Coeffient by pearson by Excel ...

Fitting of polynomials & exponential curves. Experiment :1 Fitting the polynomials upto degree 3 to the given data Experiment :2 Fitting the polynomial to an exponential curve of the form y = aebx

  #LAB-5 #Program 1 x= 1 : 6 y=c( 5 , 70 , 150 , 380 , 550 , 740 ) fitsline=lm(y ~ x) fitsline plot(x,y,pch= 19 ,ylim=c( 0 , 800 )) lines(x,fitted(fitsline),col= 'red' ,type= 'b' ) #b(Quardic_line) x= 1 : 6 y=c( 5 , 70 , 150 , 380 , 550 , 740 ) fitquaratic=lm(y ~ poly(x, 2 ,raw= TRUE )) fitquaratic plot(x,y,pch= 19 ,ylim=c( 0 , 800 )) lines(x,fitted(fitquaratic),col= 'blue' ,type= 'b' ) #Cubic x= 1 : 6 y=c( 5 , 70 , 150 , 380 , 550 , 740 ) fitcubic=lm(y ~ poly(x, 3 ,raw= TRUE )) fitcubic plot(x,y,pch= 19 ,ylim=c( 0 , 800 )) lines(x,fitted(fitcubic),col= 'green' ,type= 'b' ) #Program 2: x=c( 32 , 64 , 96 , 118 , 126 , 144 , 152.5 , 158 ) y=c( 99.5 , 104.8 , 108.5 , 100 , 86 , 64 , 35.3 , 15 ) fitstline=lm(y ~ x) fitstline plot(x,y,pch= 19 ,ylim=c( 0 , 120 )) lines(x,fitted(fitstline),col= 'red' ,type= 'b' ) #Quadratic x=c( 32 , 64 , 96 , 118 , 126 , 144 , 152.5 , 158 ) y=c( 99.5 , 104.8 , 108.5 , 100 , 86 , 64 , 35.3 , 15 )...

Measures of Dispersion. Range, Coefficient of range, Quartile Deviation, Mean deviation, Variance and Coeff. Of variation. Experiment :1 For ungrouped data. Experiment :2 For grouped data without class intervals. Experiment :3 For grouped data with class intervals.

  #Measure of Dispersion #Program-1 #Range x=c( 25 , 29 , 30 , 17 , 19 , 30 , 18 , 28 , 31 , 33 , 26 , 28 ) r=range(x) r diff(r) #Coeffient of Range x=c( 25 , 29 , 30 , 17 , 19 , 30 , 18 , 28 , 31 , 33 , 26 , 28 ) r=range(x) crange=(max(x)-min(x))/(max(x)+min(x)) crange #Quartile Deviation x=c( 25 , 29 , 30 , 17 , 19 , 30 , 18 , 28 , 31 , 33 , 26 , 28 ) qd=((quantile(x, 0.75 )-quantile(x, 0.25 )))/ 2 qd #Mean deviation from Median x=c( 25 , 29 , 30 , 17 , 19 , 30 , 18 , 28 , 31 , 33 , 26 , 28 ) mad(x) #Coeff. of Mean deviation from Median x=c( 25 , 29 , 30 , 17 , 19 , 30 , 18 , 28 , 31 , 33 , 26 , 28 ) cmd=mad(x)/median(x) cmd #Variance x=c( 25 , 29 , 30 , 17 , 19 , 30 , 18 , 28 , 31 , 33 , 26 , 28 ) n= 12 var(x) var(x)*(n- 1 )/n #Standard Deviation x=c( 25 , 29 , 30 , 17 , 19 , 30 , 18 , 28 , 31 , 33 , 26 , 28 ) sd(x) #Program 2 #Range grp=seq( 0 , 15 , 1 ) f=c( 5 , 14 , 21 , 23 , 60 , 80 , 86 , 125 , 112 , 93 , 56 , 43 , 32 , 24 , 22 , 16 ) data=rep(grp,f) r=range(data) diff(r) #...

Problems based on measures of central tendency. Mean, Geometric mean, Harmonic mean, median, mode & Quartiles Experiment :1 For Ungrouped data. Experiment :2 For Ungrouped data with NA. Experiment :3 Forgrouped data without class intervals. Experiment :4 For grouped data with class intervals.

  #Psych Package install.packages( "psych" ) library( "psych" ) #UnGrouped Data #Arithmetic_Mean rainfall=c( 10 , 10 , 10 , 10 , 10 , 560 , 640 , 520 , 320 , 90 , 20 , 10 ) mean(rainfall) #Geometric_Mean rainfall=c( 10 , 10 , 10 , 10 , 10 , 560 , 640 , 520 , 320 , 90 , 20 , 10 ) geometric.mean(rainfall) #Harmonic_Mean rainfall=c( 10 , 10 , 10 , 10 , 10 , 560 , 640 , 520 , 320 , 90 , 20 , 10 ) harmonic.mean(rainfall) #Median rainfall=c( 10 , 10 , 10 , 10 , 10 , 560 , 640 , 520 , 320 , 90 , 20 , 10 ) median(rainfall) #Mode rainfall=c( 10 , 10 , 10 , 10 , 10 , 560 , 640 , 520 , 320 , 90 , 20 , 10 ) mode= function (x) {   uniqx=unique (x)   uniqx[which.max(tabulate(match(x,uniqx)))] } mode(rainfall) #Modeest install.packages( "modeest" ) library(modeest) rainfall=c( 10 , 10 , 10 , 10 , 10 , 560 , 640 , 520 , 320 , 90 , 20 , 10 ) mode=mfv(rainfall) if (length(rainfall)==length(unique(rainfall))) print( "Mode does not exist" ) else mode #Quantile_25% ...

Graphical representation of data. Experiment :1 Bar Graph Experiment :2 Pie Graph Experiment :3 Histograms Experiment :4 Boxplot

df=data.frame(Name=c( "John" , "Bill" , "Maria" , "Tom" , "Emma" ),age=c( 23 , 41 , 32 , 55 , 40 )) df write.csv(df, "people.csv" ,row.names= FALSE ) #Built-in Data data(mtcars) head(mtcars, 6 ) #BAR Graph x=c( "Punjab" , "Harayana" , "U.P" , "Gujarat" , "Bihar" , "Karnataka" ) y=c( 728 , 943 , 1469 , 2903 , 2153 , 2276 ) barplot(y,names.arg=x,col= "red" ,main= "Yield of rice in Kg. Per Acre in various states of india" ,xlab= "States" ,ylab= "Yield" ) #Multiple Bar Graph clg=c( "A" , "B" , "C" , "D" ) clgA=c( 120 , 260 , 500 ) clgB=c( 100 , 180 , 650 ) clgC=c( 140 , 300 , 850 ) clgD=c( 750 , 900 , 300 ) d=data.frame(clgA,clgB,clgC,clgD) d1=as.matrix(d) barplot(d1,beside=T,names.arg=clg,xlab= "College" ,ylab= "No.Of Students" ,col=c( "orange" , "white...