0% found this document useful (0 votes)
85 views15 pages

Assignment 2 1

The document provides instructions for analyzing lung capacity data using R programming. It includes: 1) Loading and viewing the lung capacity data file. The data contains measurements on 725 individuals. 2) Using functions like str, View, and fivenum to examine the structure and summarize each variable. Variables include lung capacity, age, height, and smoking status. 3) Creating boxplots and histograms to visualize the distribution of lung capacity, age, and height.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views15 pages

Assignment 2 1

The document provides instructions for analyzing lung capacity data using R programming. It includes: 1) Loading and viewing the lung capacity data file. The data contains measurements on 725 individuals. 2) Using functions like str, View, and fivenum to examine the structure and summarize each variable. Variables include lung capacity, age, height, and smoking status. 3) Creating boxplots and histograms to visualize the distribution of lung capacity, age, and height.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, LAHORE

Assignment 2 (MA-244L): PROBABILITY & STATISTICS


B.Sc. IME 4th SEMESTER (Session: 2020)

Due Date: 26/07/2020 Session: FALL 2021


Weightage: 40% Maximum Marks: 40
Q1 Initialize a natural by your one or two-digit roll number. Increase it by one unit. then print
those numbers where each one is obtained by multiplying a number by its immediate next
one. (i) Use the while loop and cat command for the next ten natural numbers.
(ii) then call a user defined function (defined below) in the console window to find the sum of
their components like
2019-ME-01
1st com=x=2+0+1+9=12
2nd com=y=M+E=13+5=18

Code
fibwhile<-function(n){
+ if(n==0) return(0)
+ f<-c(1,2)
+ while(n+1>length(f)){
+ l<-length(f)
+ x<-f[l]*f[l-1]
+ f<-c(f,x)
+ }
+ f
+}
>
> fibwhile(1)
[1] 1 2
> fibwhile(2)
[1] 1 2 2
> fibwhile(3)
[1] 1 2 2 4
> fibwhile(4)
[1] 1 2 2 4 8
> fibwhile(5)
[1] 1 2 2 4 8 32
> fibwhile(6)
[1] 1 2 2 4 8 32 256
> fibwhile(7)
[1] 1 2 2 4 8 32 256 8192

Q2: Using the programming,


(i) call the data file of lungs Capacity data
(ii) Explain its structure with the help of programming.
(iii) How to view its file.

Then for each of the subcomponents of lungs capacity data

(iv) How to call each of its components one by one.


(v) Use five-point summary.
(vi) Classify the data numerically, categorically and etc.
(vii) Make the box plots.
(viii) Make the histograms.

library(readxl)

> LungCapData <- read_excel("D:/Industrial and Manufacturing Engineering/Semester no 4/Probability


and Statistics/Lab/LungCapData.xls")

> View(LungCapData)

> str(LungCapData)

tibble [725 x 6] (S3: tbl_df/tbl/data.frame)

$ LungCap : num [1:725] 6.47 10.12 9.55 11.12 4.8 ...

$ Age : num [1:725] 6 18 16 14 5 11 8 11 15 11 ...

$ Height : num [1:725] 62.1 74.7 69.7 71 56.9 58.7 63.3 70.4 70.5 59.2 ...

$ Smoke : chr [1:725] "no" "yes" "no" "no" ...

$ Gender : chr [1:725] "male" "female" "female" "male" ...

$ Caesarean: chr [1:725] "no" "no" "yes" "no" ...


>

>

>

> min(LungCapData$LungCap)

[1] 0.507

> max(LungCapData$LungCap)

[1] 14.675

> median(LungCapData$LungCap)

[1] 8

> mode(LungCapData$LungCap)

[1] "numeric"

> quantile(LungCapData$LungCap)

0% 25% 50% 75% 100%

0.507 6.150 8.000 9.800 14.675

> quantile(LungCapData$LungCap,0)

0%

0.507

> quantile(LungCapData$LungCap,25)

Error in quantile.default(LungCapData$LungCap, 25) :

'probs' outside [0,1]

> quantile(LungCapData$LungCap,.25)

25%

6.15

>

>

>

>

>

>
>

>

> min(LungCapData$LungCap)

[1] 0.507

> max(LungCapData$LungCap)

[1] 14.675

> median(LungCapData$LungCap)

[1] 8

> mode(LungCapData$LungCap)

[1] "numeric"

> quantile(LungCapData$LungCap)

0% 25% 50% 75% 100%

0.507 6.150 8.000 9.800 14.675

> quantile(LungCapData$LungCap,0)

0%

0.507

> quantile(LungCapData$LungCap,.25)

25%

6.15

> quantile(LungCapData$LungCap,.50)

50%

> quantile(LungCapData$LungCap,0.75)

75%

9.8

> quantile(LungCapData$LungCap,1)

100%

14.675

>
>

> min(LungCapData$Age)

[1] 3

> max(LungCapData$Age)

[1] 19

> median(LungCapData$Age)

[1] 13

> mode(LungCapData$Age)

[1] "numeric"

> quantile(LungCapData$Age)

0% 25% 50% 75% 100%

3 9 13 15 19

> quantile(LungCapData$Age,0)

0%

> quantile(LungCapData$Age,0.25)

25%

> quantile(LungCapData$Age,0.50)

50%

13

> quantile(LungCapData$Age,0.75)

75%

15

> quantile(LungCapData$Age,1)

100%

19

>

>
>

> min(LungCapData$Height)

[1] 45.3

> max(LungCapData$Height)

[1] 81.8

> median(LungCapData$Height)

[1] 65.4

> mode(LungCapData$Height)

[1] "numeric"

> quantile(LungCapData$Height)

0% 25% 50% 75% 100%

45.3 59.9 65.4 70.3 81.8

> quantile(LungCapData$Height,0)

0%

45.3

> quantile(LungCapData$Height,0.25)

25%

59.9

> quantile(LungCapData$Height,0.50)

50%

65.4

> quantile(LungCapData$Height,0.75)

75%

70.3

> quantile(LungCapData$Height,1)

100%

81.8

>

>
>

>

> fivenum(LungCapData)

Error:

! Can't combine `LungCap` <double> and `Smoke` <character>.

Run `rlang::last_error()` to see where the error occurred.

Warning message:

In xtfrm.data.frame(x) : cannot xtfrm data frames

>

>

>

>

> fivenum(LungCapData$LungCap)

[1] 0.507 6.150 8.000 9.800 14.675

> fivenum(LungCapData$Age)

[1] 3 9 13 15 19

> fivenum(LungCapData$Height)

[1] 45.3 59.9 65.4 70.3 81.8

> fivenum(LungCapData$Smoke)

Error in x[floor(d)] + x[ceiling(d)] :

non-numeric argument to binary operator

>

>

>

>

>

> class(LungCapData$LungCap)

[1] "numeric"

> class(LungCapData$Age)
[1] "numeric"

> class(LungCapData$Height)

[1] "numeric"

> class(LungCapData$Smoke)

[1] "character"

> class(LungCapData$Gender)

[1] "character"

> class(LungCapData$Caesarean)

[1] "character"

> typeof(LungCapData$LungCap)

[1] "double"

> typeof(LungCapData$Age)

[1] "double"

> typeof(LungCapData$Height)

[1] "double"

> typeof(LungCapData$Smoke)

[1] "character"

> typeof(LungCapData$Gender)

[1] "character"

> typeof(LungCapData$Caesarean)

[1] "character"

>

>

>

>

>

> boxplot(LungCapData$LungCap,main='BOXPLOT', xlab='Boxplot', ylab='LungCap')

> boxplot(LungCapData$Age,main='BOXPLOT', xlab='Boxplot', ylab='Age')

> boxplot(LungCapData$Height,main='BOXPLOT', xlab='Boxplot', ylab='Height')


>

>

>

>

>

>

> hist(LungCapData$LungCap,main='HISTOGRAM', xlab='LungCap', ylab='Frequency')

> hist(LungCapData$Age,main='HISTOGRAM', xlab='Age', ylab='Frequency')

> hist(LungCapData$Height,main='HISTOGRAM', xlab='Height', ylab='Frequency')

>

>

>

>

> frequency(LungCapData$Age)

[1] 1

> frequency(LungCapData$Height)

[1] 1

> table(LungCapData)

, , Height = 45.3, Smoke = no, Gender = female, Caesarean = no

Age

LungCap 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0.507 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.025 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.125 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.175 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.325 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.45 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.575 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1.625 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.675 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.775 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.85 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.925 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.95 0 0 0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 0 0 0 0 0 0 0 0 0

3.75 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3.825 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3.85 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3.9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3.925 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

3.975 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.075 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.125 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.325 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.425 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.45 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

4.5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

[ reached getOption("max.print") -- omitted 284 row(s) and 2191 matrix slice(s) ]

>

>

>

>

> table(LungCapData$LungCap)
0.507 1.025 1.125 1.175 1.325 1.45 1.575 1.625 1.675 1.775 1.85 1.9

1 1 1 1 1 1 1 1 1 1 1 1

1.925 1.95 2 2.025 2.25 2.375 2.475 2.55 2.625 2.65 2.725 2.825

1 1 1 1 3 1 1 1 2 2 3 1

2.85 2.875 2.925 2.95 3.025 3.1 3.175 3.225 3.25 3.4 3.425 3.45

1 3 2 1 1 2 2 1 1 1 3 1

3.6 3.625 3.65 3.675 3.7 3.75 3.825 3.85 3.9 3.925 3.975 4.075

1 1 1 2 2 1 1 1 3 2 2 1

4.125 4.15 4.2 4.25 4.325 4.35 4.425 4.45 4.475 4.5 4.525 4.55

1 1 2 3 3 1 3 2 2 1 1 1

4.575 4.625 4.65 4.7 4.725 4.775 4.8 4.825 4.85 4.875 4.9 4.95

1 3 1 2 3 1 1 1 2 1 2 1

4.975 5.025 5.05 5.075 5.125 5.15 5.175 5.2 5.225 5.25 5.275 5.3

3 3 3 1 1 3 1 1 2 2 1 1

5.325 5.35 5.375 5.425 5.475 5.5 5.55 5.575 5.6 5.625 5.65 5.675

2 1 3 1 1 2 3 1 1 1 3 1

5.7 5.725 5.775 5.825 5.85 5.875 5.95 6 6.05 6.075 6.1 6.125

1 2 1 1 4 4 3 2 4 3 3 3

6.15 6.175 6.2 6.225 6.25 6.275 6.3 6.325 6.375 6.4 6.425 6.45

3 3 3 4 1 1 2 2 1 1 1 7

6.475 6.5 6.525 6.55 6.575 6.6 6.625 6.65 6.675 6.7 6.725 6.75

3 2 2 3 4 1 2 2 1 5 4 2

6.775 6.8 6.825 6.85 6.9 6.925 6.95 6.975 7 7.025 7.05 7.075

1 2 3 4 3 2 4 2 2 2 2 1

7.1 7.125 7.15 7.175 7.2 7.225 7.25 7.275 7.3 7.325 7.35 7.375

2 1 1 1 1 2 2 4 2 4 5 3

7.4 7.425 7.45 7.475 7.5 7.55 7.575 7.625 7.65 7.675 7.7 7.725

4 2 3 4 1 6 2 3 3 2 3 1
7.75 7.775 7.8 7.825 7.85 7.875 7.9 7.925 7.95 7.975 8 8.025

2 1 2 7 3 2 3 5 3 2 7 4

8.05 8.075 8.1 8.125 8.175 8.2 8.225 8.25 8.275 8.3 8.325 8.35

1 2 1 4 1 3 4 3 3 1 2 8

8.375 8.425 8.45 8.475 8.5 8.525 8.55 8.575 8.6 8.625 8.65 8.675

1 5 1 2 5 1 3 2 6 6 2 1

8.7 8.725 8.775 8.8 8.825 8.85 8.875 8.9 8.925 8.975 9 9.025

3 4 7 3 3 3 2 2 1 5 3 4

9.05 9.1 9.125 9.15 9.175 9.2 9.225 9.275 9.3 9.325 9.35 9.375

3 5 1 2 3 3 2 3 1 3 1 3

9.4 9.45 9.475 9.5 9.525 9.55 9.575 9.6 9.625 9.65 9.675 9.7

1 2 4 1 3 3 1 1 3 1 5 2

9.725 9.75 9.8 9.825 9.85 9.875 9.9 9.925 9.95 9.975 10 10.025

3 3 2 4 3 2 2 3 2 1 1 4

10.05 10.1 10.125 10.175 10.2 10.25 10.275 10.3 10.325 10.35 10.375 10.4

3 3 2 2 5 1 2 2 1 2 1 4

10.425 10.45 10.475 10.5 10.525 10.55 10.575 10.6 10.625 10.65 10.675 10.7

2 3 4 2 1 1 1 4 1 2 2 4

10.725 10.75 10.775 10.8 10.825 10.85 10.875 10.9 10.925 10.95 10.975 11

3 1 2 1 2 1 2 2 3 1 2 1

11.025 11.05 11.075 11.125 11.175 11.225 11.275 11.3 11.325 11.35 11.4 11.5

2 1 4 2 1 5 1 1 2 1 2 3

11.525 11.55 11.575 11.6 11.625 11.65 11.675 11.7 11.75 11.775 11.8 11.825

1 1 2 1 1 2 1 2 1 1 2 1

11.875 11.9 11.95 12.05 12.125 12.15 12.2 12.225 12.275 12.325 12.375 12.4

2 2 1 2 2 2 1 2 1 3 1 1

12.425 12.5 12.625 12.7 12.9 12.925 12.95 13.025 13.05 13.075 13.1 13.2

2 1 1 1 1 1 2 1 1 1 1 1

13.325 13.375 13.875 14.375 14.55 14.675


1 3 1 1 1 1

> table(LungCapData$Age)

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

13 6 20 25 37 41 40 51 58 68 69 56 64 54 43 43 37

> table(LungCapData$Height)

45.3 46.6 47 47.4 47.7 47.8 48 48.1 48.2 48.7 48.8 48.9 49 49.2 49.3 49.8

1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1

49.9 50.3 50.5 50.7 51 51.1 51.2 51.4 51.5 51.6 51.7 51.9 52 52.1 52.7 52.8

1 1 1 1 3 1 1 1 2 1 3 3 2 1 3 3

52.9 53 53.2 53.3 53.5 53.6 53.7 53.8 53.9 54.2 54.3 54.5 54.7 54.8 54.9 55

2 1 2 1 1 1 3 2 2 1 1 1 1 1 3 1

55.1 55.2 55.4 55.5 55.6 55.7 55.8 55.9 56 56.1 56.2 56.3 56.4 56.5 56.6 56.7

4 1 2 4 6 2 1 2 2 3 1 2 1 2 6 2

56.8 56.9 57 57.1 57.2 57.3 57.4 57.5 57.7 57.8 57.9 58 58.3 58.4 58.5 58.6

4 2 1 2 1 3 3 1 1 1 1 3 2 5 5 1

58.7 58.8 58.9 59 59.1 59.2 59.3 59.4 59.5 59.7 59.8 59.9 60 60.1 60.2 60.3

4 3 3 2 1 6 4 4 1 4 2 4 4 3 4 2

60.4 60.5 60.6 60.7 60.8 60.9 61 61.1 61.2 61.3 61.4 61.5 61.6 61.7 61.8 61.9

5 2 3 3 1 1 2 5 3 2 6 4 4 2 4 4

62 62.1 62.2 62.3 62.4 62.5 62.6 62.7 62.8 62.9 63 63.1 63.2 63.3 63.4 63.5

4 6 1 1 3 2 6 2 4 2 4 1 3 7 6 5

63.6 63.7 63.9 64 64.1 64.2 64.3 64.4 64.5 64.6 64.7 64.8 64.9 65 65.1 65.2

4 3 4 3 5 1 2 4 2 2 6 3 3 4 4 1

65.3 65.4 65.5 65.6 65.7 65.8 65.9 66 66.1 66.2 66.3 66.4 66.5 66.6 66.7 66.8

5 8 7 6 4 4 3 6 3 3 5 5 4 4 1 2

66.9 67 67.1 67.2 67.3 67.4 67.5 67.6 67.7 67.8 67.9 68 68.1 68.2 68.3 68.4

4 1 2 3 4 4 7 4 5 3 2 4 4 5 3 4
68.5 68.6 68.7 68.8 68.9 69 69.1 69.2 69.3 69.4 69.6 69.7 69.8 69.9 70 70.1

1 6 3 4 3 4 3 3 7 6 2 4 2 3 2 2

70.2 70.3 70.4 70.5 70.6 70.8 70.9 71 71.1 71.2 71.3 71.4 71.5 71.6 71.7 71.8

3 1 4 4 2 2 5 4 4 5 2 4 4 3 2 3

71.9 72 72.1 72.2 72.3 72.4 72.5 72.6 72.7 72.8 72.9 73 73.1 73.2 73.3 73.4

5 3 1 3 1 4 5 2 1 2 2 2 3 1 3 2

73.5 73.6 73.7 73.8 73.9 74 74.1 74.2 74.3 74.4 74.5 74.6 74.7 74.8 74.9 75

7 4 2 2 3 4 1 4 2 2 1 2 2 1 3 1

75.1 75.2 75.3 75.4 75.5 75.6 75.7 75.8 75.9 76 76.1 76.2 76.3 76.4 76.5 76.6

1 2 1 2 3 2 4 3 1 1 1 2 2 1 1 2

76.8 76.9 77.2 77.4 77.6 77.7 78 78.2 78.4 78.6 78.9 79.1 79.3 79.6 79.8 80.3

2 2 1 1 1 1 1 1 2 1 2 1 1 2 1 1

80.8 81.8

1 1

> table(LungCapData$Smoke)

no yes

648 77

> table(LungCapData$Gender)

female male

358 367

> table(LungCapData$Caesarean)

no yes

561 164

>

You might also like