anjali

© All Rights Reserved

0 views

anjali

© All Rights Reserved

- MAE 200A – Homework set #1
- Scribd text
- imf financial programming
- ADVANCED PHYSICS THROUGH MATHCAD.doc
- correlation and regression.ppt
- ss-111202115106-phpapp02
- GPEBOOK.pdf
- Class Notes Sessions5-6
- Regression
- BCA_SYLLABUS_2008
- zoho2.pdf
- DECSCI2 SYLLABUS
- Forecasting
- Chapter 13 Linear regression
- 基于感性工学产品造型设计的理论分析研究.pdf
- Fe Prob Stats
- Feedback — Quiz Week 2o
- Filename: December 2014 question & solution.pdf
- content ratings
- Problem Set 1 Ec1

You are on page 1of 20

Aim: - Using R executes the basic commands, array, list and frames.

Description:-

Array:-

Array is the R data objects which can store data in more than two

dimensions. An array is creating using the array () function. It takes vectors

as input and uses the values in the dim parameter to create an array.

List:-

Lists are the R objects which contain elements of different type like numbers,

strings, vectors and another list inside it.

A list can also contain a matrix or a function as its elements. List is created

using list () function.

Data frame:-

Data frames are tabular data object. Unlike a matrix in data frame each

column can contain different mode of data. The first column can be numeric

while the second column can be character and third column can be logical. It

is a list of vectors of equal length.

Basic commands:-

mytext<-"rohan pal!"

print(mytext)

List :-

list<-list(c(3,1,4),21.3,4,sin)

print (list)

[[1]]

[1] 2 5 3

[[2]]

[1] 21.3

[[3]

Array :-

A<-array(c('yes','no'),dim=c(1,2,3))

print(A)

,,1

[,1] [,2]

,,2

[,1] [,2]

,,3

[,1] [,2]

Frame:-

f<-data. frame(

sr.no = c(1,2,3),

Name = c("Deep","Ruchi","Pooja"),

Age = c(20,19,20),

Salary = c(15000,25000,30000))

>Print (f)

1 Deep 20 15000

2 Ruchi 19 25000

3 Pooja 20 30000

Practical No-2

Aim: -Create a Matrix using R and perform the operation addition, inverse,

transpose and multiplication operations.

Description:

Matrices: a matrix is a two dimensional rectangular data set .it can be created using a vector input

to the matrix function.

Matrix inverse: matrix inversion is a process of finding the matrix b that satisfies the prior

equation for a given invertible matrix A.

Matrix transpose: the transpose matrix which is formed by turning all the rows of the given

matrix into column and vise versa.the transpose of the matrix A is written AT.

> print(A)

[,1] [,2]

[1,] 2 1

[2,] 3 2

[3,] -2 2

> print(B)

[,1] [,2]

[1,] 1 1

[2,] 4 2

[3,] -2 1

Addition matrix:

> C<-A+B

> print(C)

[,1] [,2]

[1,] 3 2

[2,] 7 4

[3,] -4 3

Inverse matrix:

> E<-matrix(c(2,1,6,1,3,4,6,4,-2),3,3)

> print(E)

[1,] 2 1 6

[2,] 1 3 4

[3,] 6 4 -2

> AI<-solve(E)

> print(AI)

Transpose matrix:

> AT<-(A)

> print(AT)

[,1] [,2]

[1,] 2 1

[2,] 3 2

[3,] -2 2

> ATT<-t(AT)

> print(ATT)

[1,] 2 3 -2

[2,] 1 2 2

Multiplication matrix:

> D<-A*B

> print(D)

[,1] [,2]

[1,] 2 1

[2,] 12 4

[3,] 4 2

Practical No-3

Aim :- Using R execute the statistical analysis. Mean, Median , Mode ,

Quartiles , Range , Integer Quartile , Range Histogram. Using R import data

from EXCEL/- CSV File & perform the above functions.

Description :-

1. Mean :- Mean calculated by taking the sum of the values and dividing

with the number of values in a data series. The function mean()is used to

calculate this in R.

2. Median :- Median most value in the data series is called as median. The

function median()is used to calculate this in R.

3. Mode :- The mode is the value that has highest number of occurrences in

a set of data. Unlike mean and median, mode can have both numeric and

character data. R does not have a standard in-built function to calculate

mode. So we create a user function to calculate mode of a data set in R.

4. Range :-

5. Interquartile :-

Solution :-

>data<-read.csv(file.choose(,) , header = T)

>data

Mean of salary :-

>print(mean(data $ salary))

Median of salary :-

>print(median(data $ salary))

Mode :-

>getmode<-function(v){

+uniqv<-uniqv(v)

+uniqv[which.max(tabulate(match(v , uniqv)))]

Quartile :-

>quartile(data $ salary)

Interquartile :-

>print(IQR(data $ salary))

Histogram :-

>hist(data $ salary)

OUTPUT:-

11 A 20000

22 B 30000

33 C 40000

44 D 25000

Mean :-

[1] 28750

Median:-

[1] 27500

Mode :-

[1] 20000

Quartile :-

Interquartile Range :-

[1] 8750

Practical No- 4

Aim:-Using R import the data from excel /.CSC file and per for m the above

function.

Example:

> data1

No. X

1 2 12

2 2 7

3 3 3

4 4 4

5 5 2

6 6 18

7 7 2

8 8 54

9 9 -21

10 10 8

11 11 -5

> mean( x)

[1] 7.03

[1] 2.65

Practical no-5

Aim :- Using R import data from EXCEL/- CSV File & Calculate the Standard

Deviation , Variance , Co- Variance.

Description :-

Solution :-

>data

Standard Deviation :-

>print(sd(d $ marks))

Variance :-

>print(var(d $ marks))

Co-Variance :-

OUTPUT:-

Roll.no Marks

11 50

22 65

33 45

44 85

55 70

Standard deviation :-

[1] 16.40681

Variance :-

[1] 257.5

Co-variance :-

[1] -1

Practical No-6

Aim :- Using R import the data from excel.csv file and draw the skewness.

Description :-

degree of distortion from symmetry or in other word . Skewness is concerned

with the shape of the curve and not its size .

Solution :-

To import data from excel to R:

> print(data)

Skewness:-

> library(moments)

> result=skewness(n$prize)

> print(result)

Output:-

Maths Prize

11 350

22 300

33 650

44 1000

55 850

Skewness:-

[1] 0.1832912

Practical No- 7

Aim:-Import the data from excel /.csv and perform the hypothetical testing.

Problem: Suppose the manufacturer claims that the mean lifetime of a light

bulb is more than 10,000 hours. In a sample of 30 light bulbs, it was found

that they only last 9,900 hours on average. Assume the population standard

deviation is 120 hours . At .05 significance level, can we reject the claim by

the manufacturer?

[1] -4.564355

> alpha=.05

> t.alpha=qt(1-alpha,df=n-1)

Problem:Suppose the food label on a cookie bag states that there is at most

2 grams of saturated fat in a single cookie. In a sample of 35 cookie, it is

found that the mean amount of saturated fat per cookie is 2.1grams. Assume

that the population standard deviation is 0.25 grams. At 0.05 significance

level,can we reject the claim on food label.

Solution:

> xbar<-2.1

> mu0<-2

> Sigma<-0.25

> n<-35

> z=(xbar-mu0)/(Sigma/sqrt(n))

>z

[1] 2.366432

> z.alpha<-qnorm(1-alpha)

> alpha<-0.05

> z.alpha

[1] 1.644854

Practical No-8

Aim:-Import the data from Excel/.CSV and perform the Chi- squared Test.

> library("MASS")

TRUE)),graphics=TRUE)

+ if(nchar(pkg)) library(pkg, character.only=TRUE)})

> print(str(Cars93))

Output:

4 4 5 ...

1 6 24 54 74 73 35 ...

3 2 2 3 2 ...

$ Min.Price : num 12.9 29.2 25.9 30.8 23.7 14.2 19.9 22.6 26.3

33 ...

$ Price : num 15.9 33.9 29.1 37.7 30 15.7 20.8 23.7 26.3

34.7 ...

$ Max.Price : num 18.8 38.7 32.3 44.6 36.2 17.3 21.7 24.9 26.3

36.3 ...

$ EngineSize : num 1.8 3.2 2.8 2.8 3.5 2.2 3.8 5.7 3.8 4.9 ...

$ Horsepower : int 140 200 172 172 208 110 170 180 170 200 ...

$ RPM : int 6300 5500 5500 5500 5700 5200 4800 4000 4800 4100 ...

$ Rev.per.mile : int 2890 2335 2280 2535 2545 2565 1570 1320 1690

1510 ...

$ Length : int 177 195 180 193 186 189 200 216 198 206 ...

$ Wheelbase : int 102 115 102 106 109 105 111 116 108 114 ...

$ Weight : int 2705 3560 3375 3405 3640 2880 3470 4105 3495 3620 ...

NULL

Chisquare Code:

> library("MASS")

> car.data<-data.frame(Cars93$AirBags,Cars93$Type)

> car.data=table(Cars93$AirBags,Cars93$Type)

> print(car.data)

> print(chisq.test(car.data))

Output:

Driver only 9 7 11 5 8 3

None 5 0 4 16 3 6

Pearson's Chi-squared test

data: car.data

each question has 5 possible answers, and only 1 of them is correct. Find the

probability of having 4 or less correct answers if a student attempt to every

question at random.

attempts, we apply the function dbinom with x=0,...,4.

> dbinom(0,size=12,prob=0.2)+

+ dbinom(1,size=12,prob=0.2)+

+ dbinom(2,size=12,prob=0.2)+

+ dbinom(3,size=12,prob=0.2)+

distribution pbinom.

Normal distribution:

Q.Assume that the test scores of a college entrance exam fits a normal

distribution. Furthermore, the mean test score is 72 and the S.D is 15.2.

What is the percentage of students scoring 84 or more in the exam?

Solution:We apply the function pnorm of the normal distribution with mean

72 and S.D

Practical No-9

AIM: Using R performs the binomial and normal distribution on the data.

Binomial distribution :The binomial distribution model deals with finding the

probability of success of an experiment.

dbinom()

> x<-seq(0,50,by=1)

> y<-dbinom(x,50,0.5)

> png(file="dbinom.png")

> plot(x,y)

Practical No-10

AIM: Perform the linear regression using R.

relationship model between two variables. One of these variable is called

predictor variable whose value is gathered through experiments. The other

variable is called response variable whose value is derived from the predictor

variable.

where exponent (power) of both these variables is 1. Mathematically a linear

relationship represents a straight line when plotted as a graph. A non-linear

relationship where the exponent of any variable is not equal to 1 creates a

curve.

y=ax+b

> 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)

> png(file="linearregression.png")

> dev.off()

null device

+abline(lm(x~y)),cex=1.3,pch=16,xlab="Weight in Kg",ylab="Height in cm")

Practical No-12

AIM: Compute the linear least square regression.

Problem: 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.

X 6 5 8 8 7 10 6 10 4 7

Y 8 7 7 10 5 10 8 6 8 6

Solution:

Y on X:

> x=c(6,5,8,8,7,6,10,4,9,7)

> y=c(8,7,7,10,5,10,8,6,8,6)

> plot(x,y,main="population",col="blue")

> fit=lm(x~y)

> cat("\n\n")

X on Y:

> x=c(6,5,8,8,7,6,10,4,9,7)

> y=c(8,7,7,10,5,10,8,6,8,6)

> plot(x,y,main="population",col="blue")

>

> cor(x,y)

[1] 0.2581989

> fit1=lm(y~x)

> cat("\n\n")

> attributes(fit1)

$names

$class

[1] "lm"

> abline(lm(fit1))

- MAE 200A – Homework set #1Uploaded byvsauer
- Scribd textUploaded byR Rabi Reddy
- imf financial programmingUploaded byhenry_ojae
- ADVANCED PHYSICS THROUGH MATHCAD.docUploaded byPalaniswamy Sankariah
- correlation and regression.pptUploaded bykaushalsingh20
- ss-111202115106-phpapp02Uploaded byarifmj
- GPEBOOK.pdfUploaded byDaniel Lee Eisenberg Jacobs
- Class Notes Sessions5-6Uploaded bywasimjeens
- RegressionUploaded byme_32132132
- BCA_SYLLABUS_2008Uploaded byShrikant Thakar
- zoho2.pdfUploaded byPrincy
- DECSCI2 SYLLABUSUploaded byBurnok Supol
- ForecastingUploaded byBhavanams Rao
- Chapter 13 Linear regressionUploaded byzgmngubane
- 基于感性工学产品造型设计的理论分析研究.pdfUploaded byxiaohei520
- Fe Prob StatsUploaded byKazi Moinul Islam
- Feedback — Quiz Week 2oUploaded byjcvoscrib
- Filename: December 2014 question & solution.pdfUploaded byVishak H Pillai
- content ratingsUploaded byapi-252860425
- Problem Set 1 Ec1Uploaded bygalih90
- Least Square RegressionUploaded bySamiullah Qureshi
- NA-Ch.03 Problems.pptxUploaded byMohammed
- cse11Uploaded bykhazarhayat
- Analyzing the Rainfall and Temperature Influence on Municipal Water Consumption Using Regression TechniqueUploaded byInternational Journal of Research in Engineering and Technology
- 2d arraysUploaded byalizarana
- Chapter 03Uploaded byhany_farid_2
- rabbyUploaded byRazzARaza
- GE2115_lpUploaded bysrinisanjai
- Lecture 1Uploaded byipekKK
- Control Systems LAB#01Uploaded byChampion Lodhi

- 16 Chapter 10Uploaded byHarshi Aggarwal
- 6 Sigma Sample QuestUploaded byKumaran Vel
- Norsok O-CR-001r1 Life Cycle Cost for Systems & EquipmentUploaded byspottedkelpie
- APA SpecificationUploaded byDaryl Jade Narciza
- Use of Groups in School Social Work- Group Work and Group ProcessUploaded byAmen Xavier Kaushal
- Sound Influence on Landscape ValuesUploaded byBlogue Menos Um Carro
- HW4Solutions.pdfUploaded byDavid Lee
- ES9-Chap06Uploaded bynikowawa
- APICS_MPR 经典350题题库Uploaded bysoiree
- Pg 1591-1634 Chap5-RawMealHomogenization TextUploaded byMKPashaPasha
- Probability applications in Mechanical Engineering design.pdfUploaded byMyameSirame
- How to Benchmark SalesUploaded byAgnes Yu
- Pages From First Aid (USMLE Step1) [2019]Uploaded byGeorge Russell
- Social Equality and State Welfare Effort- LidoUploaded byPedro Dias
- Pit and Pendulum JournalUploaded bysoadquake981
- CNAF NAE GB Student Book (Ver 1070)Uploaded byJoshua Stuart
- testreviewUploaded byapi-274198862
- 1-IntroductionToAdjustmentUploaded bySylvia Iping
- Circadian Rhythms in Octopus VulgarisUploaded byAlexandre Jassoud
- CourseUploaded byMANUEL7000
- 1 parámetros estadísticos.pdfUploaded byAbner BS
- PAPER [ENG] - An Electrophysiological Study of the Sequential Water SwallowingUploaded byAldo Nicholas Hip Naranjo
- A2-Level Biology, Unit 4 notesUploaded byBhanhee Kim
- question 2014.docxUploaded byAshif Iqubal
- xbar-r-75-925_9Uploaded byCurtis Smith
- Writing the First Draft of Your Science PaperUploaded byOsman Ervan
- antivola.docxUploaded bycrisjava
- readymix concrete BS EN 206-1Uploaded byAjit Singh Rathore
- ExpertLottoUploaded bydoggy220
- Central Tendency & DispersionUploaded byAshraf Hossain