First commit

This commit is contained in:
Andrew
2023-01-07 20:58:44 +02:00
commit 75313f3f05
1571 changed files with 928288 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
x <- seq(30, 35, by = .1)
y <- dnorm(x, mean = 30, sd = 4)
png(file = "dnorm.png")
plot(x, y)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,11 @@
carat,cut,color,clarity,depth,table,price,x,y,z,
1.38,Premium,J,SI1,59,59,5912,7.38,7.32,4.34,
0.52,Very,Good,G,VVS2,61.8,59,1911,5.13,5.16,3.18
0.36,Premium,F,VS2,62,59,629,4.51,4.56,2.81,
0.9,Very,Good,E,VS2,63.8,55,4598,6.11,6.18,3.92
0.24,Very,Good,E,VVS1,63.1,55,485,3.96,4,2.51
1.07,Ideal,F,VS1,62.1,55,7850,6.58,6.56,4.08,
0.31,Ideal,F,VVS1,62.3,54,840,4.34,4.36,2.71,
0.91,Very,Good,G,SI1,63.5,58,4081,6.15,6.04,3.87
0.31,Premium,G,VVS1,60.4,59,1046,4.41,4.37,2.65,
0.26,Good,E,VVS2,63.1,59,599,4.04,4.08,2.56,
1 carat cut color clarity depth table price x y z
2 1.38 Premium J SI1 59 59 5912 7.38 7.32 4.34
3 0.52 Very Good G VVS2 61.8 59 1911 5.13 5.16 3.18
4 0.36 Premium F VS2 62 59 629 4.51 4.56 2.81
5 0.9 Very Good E VS2 63.8 55 4598 6.11 6.18 3.92
6 0.24 Very Good E VVS1 63.1 55 485 3.96 4 2.51
7 1.07 Ideal F VS1 62.1 55 7850 6.58 6.56 4.08
8 0.31 Ideal F VVS1 62.3 54 840 4.34 4.36 2.71
9 0.91 Very Good G SI1 63.5 58 4081 6.15 6.04 3.87
10 0.31 Premium G VVS1 60.4 59 1046 4.41 4.37 2.65
11 0.26 Good E VVS2 63.1 59 599 4.04 4.08 2.56

View File

@@ -0,0 +1,166 @@
# A comment begins with #
# Some useful keyboard shortcuts in R Studio:
# CTRL+ENTER Executes on the command line the script line containing the cursor
# If you highlight / select text with mouse, CTRL+ENTER executes all the code
# Same applies with => Run above
# CTRL+1 Moves cursor to script window
# CTRL+2 Moves cursor to command line
# Up Arrow [In console] Cycles through previously entered commands
# TAB Activates autocomplete - very useful for paths and variable names
# F1 Searches help for the word containing the cursor
##########################
# Basic Math in R
3 + 2
4 - 6 #
log(42 / 7.3)
5 + 6 + 3 + 6 + 4 + 2 + 4 + 8 + 3 + 2 + 7
7 + 3 - 5 * 2 # multiplication "5 * 2" is done before the additions and subtractions
# Exponents
exp(2) # e^2
4^3
4**3
log(9, 3) # log to base 3 of 9
sqrt(100) # square root of 100
factorial(20)
choose(10, 3) # binomial coefficient
# R is flexible about numeric values - don't need to worry about integer vs. float
2 / 3
2.0 / 3.0
# Expressions can be placed on a single line separated by semi-colons:
2 + 3
5 * 7
3 - 7
#########################
# Storing values in variables
a <- 2
b <- 3
a / b
c <- 10.3
# Variable names are case sensitive: y is not the same as Y.
# Variable names cannot begin with numbers (e.g. 1x) or symbols (e.g. %x).
# Variable names connot contain blank spaces (use back.pay not back_pay).
##########################
# Vector Math in R
# We can use the c(...) command to create vectors from a list of values.
prices <- c(5, 10, 12, 13)
quantities <- c(100, 3, 2000, 40)
# We reference entries by their location, given in square brackets.
prices[2]
# Some functions on vectors
sum(prices)
min(prices)
max(prices)
mean(quantities)
# When vectors are of the same length, we can multiply them 'by index'
prices * quantities
##########################
# From vectors, we can create data frames
User_ID <- 1:8
# Vector with values: 1 2 3 4 5 6 7 8
Name <- c(
"John", "Lisa", "Susan", "Albert",
"Brian", "Emma", "David", "Alice"
)
# Note that you may break a vector in different lines without a problem
gender <- c(
"Male", "Female", "Female", "Male",
"Male", "Female", "Male", "Female"
)
Points <- c(56, 76, 86, 96, 73, 87, 47, 98)
Birth_year <- c(1994, 2001, 1980, 1999, 1972, 2004, 1965, 1984)
# Now we can form a data frame
df <- data.frame(User_ID, Name, gender, Birth_year)
# Click "df" in the Environment pane
# We can refer to columns of a frame by using $-symbol
df$Name # All names
# We can easily compute the age of the persons
# This computes the age of every row:
df$Age <- 2022 - df$Birth_year
# Look df frame again, there is new column "age"
View(df)
# We can find the smallest age:
min(df$Age)
# Or maximum
max(df$Age)
# Or the average
mean(df$Age)
# One can use subset function to select a "subframe"
young <- subset(df, Age < 30)
###########################
# Saving data to CSV
### To check the default working directory, use "getwd()" without quotes.
getwd()
### To change the working directory, type the path in quotes inside
### the setwd() command.
### PC Example: setwd("C:/Users/YOURUSERNAMEHERE/Desktop/")
# You can store data as
write.csv(df, "example.csv")
# Open your CSV in Excel, make some changes, save and close it
###########################
# Bringing data in from a CSV
# Download the file "diamonds.csv" from Moodle
# Store it to "Home > R_codes"
# Click that file of Files pane
# Select "Import Dataset"
# After that RStudio install couple of packages
# that are useful in importing data
# After the packages are installed you can choose "import"
# => You have a frame "diamonds".
# Visualizing data
plot(diamonds$carat, diamonds$price)
# The first parameter is x-coordinate
# The second parameter ix y-coordinate
# For more information on plots, copy-paste the following address:
# https://www.datamentor.io/r-programming/plot-function/

View File

@@ -0,0 +1,241 @@
"","timePoint","temp"
"1",1920,40.6
"2",1920.08333333333,40.8
"3",1920.16666666667,44.4
"4",1920.25,46.7
"5",1920.33333333333,54.1
"6",1920.41666666667,58.5
"7",1920.5,57.7
"8",1920.58333333333,56.4
"9",1920.66666666667,54.3
"10",1920.75,50.5
"11",1920.83333333333,42.9
"12",1920.91666666667,39.8
"13",1921,44.2
"14",1921.08333333333,39.8
"15",1921.16666666667,45.1
"16",1921.25,47
"17",1921.33333333333,54.1
"18",1921.41666666667,58.7
"19",1921.5,66.3
"20",1921.58333333333,59.9
"21",1921.66666666667,57
"22",1921.75,54.2
"23",1921.83333333333,39.7
"24",1921.91666666667,42.8
"25",1922,37.5
"26",1922.08333333333,38.7
"27",1922.16666666667,39.5
"28",1922.25,42.1
"29",1922.33333333333,55.7
"30",1922.41666666667,57.8
"31",1922.5,56.8
"32",1922.58333333333,54.3
"33",1922.66666666667,54.3
"34",1922.75,47.1
"35",1922.83333333333,41.8
"36",1922.91666666667,41.7
"37",1923,41.8
"38",1923.08333333333,40.1
"39",1923.16666666667,42.9
"40",1923.25,45.8
"41",1923.33333333333,49.2
"42",1923.41666666667,52.7
"43",1923.5,64.2
"44",1923.58333333333,59.6
"45",1923.66666666667,54.4
"46",1923.75,49.2
"47",1923.83333333333,36.3
"48",1923.91666666667,37.6
"49",1924,39.3
"50",1924.08333333333,37.5
"51",1924.16666666667,38.3
"52",1924.25,45.5
"53",1924.33333333333,53.2
"54",1924.41666666667,57.7
"55",1924.5,60.8
"56",1924.58333333333,58.2
"57",1924.66666666667,56.4
"58",1924.75,49.8
"59",1924.83333333333,44.4
"60",1924.91666666667,43.6
"61",1925,40
"62",1925.08333333333,40.5
"63",1925.16666666667,40.8
"64",1925.25,45.1
"65",1925.33333333333,53.8
"66",1925.41666666667,59.4
"67",1925.5,63.5
"68",1925.58333333333,61
"69",1925.66666666667,53
"70",1925.75,50
"71",1925.83333333333,38.1
"72",1925.91666666667,36.3
"73",1926,39.2
"74",1926.08333333333,43.4
"75",1926.16666666667,43.4
"76",1926.25,48.9
"77",1926.33333333333,50.6
"78",1926.41666666667,56.8
"79",1926.5,62.5
"80",1926.58333333333,62
"81",1926.66666666667,57.5
"82",1926.75,46.7
"83",1926.83333333333,41.6
"84",1926.91666666667,39.8
"85",1927,39.4
"86",1927.08333333333,38.5
"87",1927.16666666667,45.3
"88",1927.25,47.1
"89",1927.33333333333,51.7
"90",1927.41666666667,55
"91",1927.5,60.4
"92",1927.58333333333,60.5
"93",1927.66666666667,54.7
"94",1927.75,50.3
"95",1927.83333333333,42.3
"96",1927.91666666667,35.2
"97",1928,40.8
"98",1928.08333333333,41.1
"99",1928.16666666667,42.8
"100",1928.25,47.3
"101",1928.33333333333,50.9
"102",1928.41666666667,56.4
"103",1928.5,62.2
"104",1928.58333333333,60.5
"105",1928.66666666667,55.4
"106",1928.75,50.2
"107",1928.83333333333,43
"108",1928.91666666667,37.3
"109",1929,34.8
"110",1929.08333333333,31.3
"111",1929.16666666667,41
"112",1929.25,43.9
"113",1929.33333333333,53.1
"114",1929.41666666667,56.9
"115",1929.5,62.5
"116",1929.58333333333,60.3
"117",1929.66666666667,59.8
"118",1929.75,49.2
"119",1929.83333333333,42.9
"120",1929.91666666667,41.9
"121",1930,41.6
"122",1930.08333333333,37.1
"123",1930.16666666667,41.2
"124",1930.25,46.9
"125",1930.33333333333,51.2
"126",1930.41666666667,60.4
"127",1930.5,60.1
"128",1930.58333333333,61.6
"129",1930.66666666667,57
"130",1930.75,50.9
"131",1930.83333333333,43
"132",1930.91666666667,38.8
"133",1931,37.1
"134",1931.08333333333,38.4
"135",1931.16666666667,38.4
"136",1931.25,46.5
"137",1931.33333333333,53.5
"138",1931.41666666667,58.4
"139",1931.5,60.6
"140",1931.58333333333,58.2
"141",1931.66666666667,53.8
"142",1931.75,46.6
"143",1931.83333333333,45.5
"144",1931.91666666667,40.6
"145",1932,42.4
"146",1932.08333333333,38.4
"147",1932.16666666667,40.3
"148",1932.25,44.6
"149",1932.33333333333,50.9
"150",1932.41666666667,57
"151",1932.5,62.1
"152",1932.58333333333,63.5
"153",1932.66666666667,56.3
"154",1932.75,47.3
"155",1932.83333333333,43.6
"156",1932.91666666667,41.8
"157",1933,36.2
"158",1933.08333333333,39.3
"159",1933.16666666667,44.5
"160",1933.25,48.7
"161",1933.33333333333,54.2
"162",1933.41666666667,60.8
"163",1933.5,65.5
"164",1933.58333333333,64.9
"165",1933.66666666667,60.1
"166",1933.75,50.2
"167",1933.83333333333,42.1
"168",1933.91666666667,35.8
"169",1934,39.4
"170",1934.08333333333,38.2
"171",1934.16666666667,40.4
"172",1934.25,46.9
"173",1934.33333333333,53.4
"174",1934.41666666667,59.6
"175",1934.5,66.5
"176",1934.58333333333,60.4
"177",1934.66666666667,59.2
"178",1934.75,51.2
"179",1934.83333333333,42.8
"180",1934.91666666667,45.8
"181",1935,40
"182",1935.08333333333,42.6
"183",1935.16666666667,43.5
"184",1935.25,47.1
"185",1935.33333333333,50
"186",1935.41666666667,60.5
"187",1935.5,64.6
"188",1935.58333333333,64
"189",1935.66666666667,56.8
"190",1935.75,48.6
"191",1935.83333333333,44.2
"192",1935.91666666667,36.4
"193",1936,37.3
"194",1936.08333333333,35
"195",1936.16666666667,44
"196",1936.25,43.9
"197",1936.33333333333,52.7
"198",1936.41666666667,58.6
"199",1936.5,60
"200",1936.58333333333,61.1
"201",1936.66666666667,58.1
"202",1936.75,49.6
"203",1936.83333333333,41.6
"204",1936.91666666667,41.3
"205",1937,40.8
"206",1937.08333333333,41
"207",1937.16666666667,38.4
"208",1937.25,47.4
"209",1937.33333333333,54.1
"210",1937.41666666667,58.6
"211",1937.5,61.4
"212",1937.58333333333,61.8
"213",1937.66666666667,56.3
"214",1937.75,50.9
"215",1937.83333333333,41.4
"216",1937.91666666667,37.1
"217",1938,42.1
"218",1938.08333333333,41.2
"219",1938.16666666667,47.3
"220",1938.25,46.6
"221",1938.33333333333,52.4
"222",1938.41666666667,59
"223",1938.5,59.6
"224",1938.58333333333,60.4
"225",1938.66666666667,57
"226",1938.75,50.7
"227",1938.83333333333,47.8
"228",1938.91666666667,39.2
"229",1939,39.4
"230",1939.08333333333,40.9
"231",1939.16666666667,42.4
"232",1939.25,47.8
"233",1939.33333333333,52.4
"234",1939.41666666667,58
"235",1939.5,60.7
"236",1939.58333333333,61.8
"237",1939.66666666667,58.2
"238",1939.75,46.7
"239",1939.83333333333,46.6
"240",1939.91666666667,37.8
1 timePoint temp
2 1 1920 40.6
3 2 1920.08333333333 40.8
4 3 1920.16666666667 44.4
5 4 1920.25 46.7
6 5 1920.33333333333 54.1
7 6 1920.41666666667 58.5
8 7 1920.5 57.7
9 8 1920.58333333333 56.4
10 9 1920.66666666667 54.3
11 10 1920.75 50.5
12 11 1920.83333333333 42.9
13 12 1920.91666666667 39.8
14 13 1921 44.2
15 14 1921.08333333333 39.8
16 15 1921.16666666667 45.1
17 16 1921.25 47
18 17 1921.33333333333 54.1
19 18 1921.41666666667 58.7
20 19 1921.5 66.3
21 20 1921.58333333333 59.9
22 21 1921.66666666667 57
23 22 1921.75 54.2
24 23 1921.83333333333 39.7
25 24 1921.91666666667 42.8
26 25 1922 37.5
27 26 1922.08333333333 38.7
28 27 1922.16666666667 39.5
29 28 1922.25 42.1
30 29 1922.33333333333 55.7
31 30 1922.41666666667 57.8
32 31 1922.5 56.8
33 32 1922.58333333333 54.3
34 33 1922.66666666667 54.3
35 34 1922.75 47.1
36 35 1922.83333333333 41.8
37 36 1922.91666666667 41.7
38 37 1923 41.8
39 38 1923.08333333333 40.1
40 39 1923.16666666667 42.9
41 40 1923.25 45.8
42 41 1923.33333333333 49.2
43 42 1923.41666666667 52.7
44 43 1923.5 64.2
45 44 1923.58333333333 59.6
46 45 1923.66666666667 54.4
47 46 1923.75 49.2
48 47 1923.83333333333 36.3
49 48 1923.91666666667 37.6
50 49 1924 39.3
51 50 1924.08333333333 37.5
52 51 1924.16666666667 38.3
53 52 1924.25 45.5
54 53 1924.33333333333 53.2
55 54 1924.41666666667 57.7
56 55 1924.5 60.8
57 56 1924.58333333333 58.2
58 57 1924.66666666667 56.4
59 58 1924.75 49.8
60 59 1924.83333333333 44.4
61 60 1924.91666666667 43.6
62 61 1925 40
63 62 1925.08333333333 40.5
64 63 1925.16666666667 40.8
65 64 1925.25 45.1
66 65 1925.33333333333 53.8
67 66 1925.41666666667 59.4
68 67 1925.5 63.5
69 68 1925.58333333333 61
70 69 1925.66666666667 53
71 70 1925.75 50
72 71 1925.83333333333 38.1
73 72 1925.91666666667 36.3
74 73 1926 39.2
75 74 1926.08333333333 43.4
76 75 1926.16666666667 43.4
77 76 1926.25 48.9
78 77 1926.33333333333 50.6
79 78 1926.41666666667 56.8
80 79 1926.5 62.5
81 80 1926.58333333333 62
82 81 1926.66666666667 57.5
83 82 1926.75 46.7
84 83 1926.83333333333 41.6
85 84 1926.91666666667 39.8
86 85 1927 39.4
87 86 1927.08333333333 38.5
88 87 1927.16666666667 45.3
89 88 1927.25 47.1
90 89 1927.33333333333 51.7
91 90 1927.41666666667 55
92 91 1927.5 60.4
93 92 1927.58333333333 60.5
94 93 1927.66666666667 54.7
95 94 1927.75 50.3
96 95 1927.83333333333 42.3
97 96 1927.91666666667 35.2
98 97 1928 40.8
99 98 1928.08333333333 41.1
100 99 1928.16666666667 42.8
101 100 1928.25 47.3
102 101 1928.33333333333 50.9
103 102 1928.41666666667 56.4
104 103 1928.5 62.2
105 104 1928.58333333333 60.5
106 105 1928.66666666667 55.4
107 106 1928.75 50.2
108 107 1928.83333333333 43
109 108 1928.91666666667 37.3
110 109 1929 34.8
111 110 1929.08333333333 31.3
112 111 1929.16666666667 41
113 112 1929.25 43.9
114 113 1929.33333333333 53.1
115 114 1929.41666666667 56.9
116 115 1929.5 62.5
117 116 1929.58333333333 60.3
118 117 1929.66666666667 59.8
119 118 1929.75 49.2
120 119 1929.83333333333 42.9
121 120 1929.91666666667 41.9
122 121 1930 41.6
123 122 1930.08333333333 37.1
124 123 1930.16666666667 41.2
125 124 1930.25 46.9
126 125 1930.33333333333 51.2
127 126 1930.41666666667 60.4
128 127 1930.5 60.1
129 128 1930.58333333333 61.6
130 129 1930.66666666667 57
131 130 1930.75 50.9
132 131 1930.83333333333 43
133 132 1930.91666666667 38.8
134 133 1931 37.1
135 134 1931.08333333333 38.4
136 135 1931.16666666667 38.4
137 136 1931.25 46.5
138 137 1931.33333333333 53.5
139 138 1931.41666666667 58.4
140 139 1931.5 60.6
141 140 1931.58333333333 58.2
142 141 1931.66666666667 53.8
143 142 1931.75 46.6
144 143 1931.83333333333 45.5
145 144 1931.91666666667 40.6
146 145 1932 42.4
147 146 1932.08333333333 38.4
148 147 1932.16666666667 40.3
149 148 1932.25 44.6
150 149 1932.33333333333 50.9
151 150 1932.41666666667 57
152 151 1932.5 62.1
153 152 1932.58333333333 63.5
154 153 1932.66666666667 56.3
155 154 1932.75 47.3
156 155 1932.83333333333 43.6
157 156 1932.91666666667 41.8
158 157 1933 36.2
159 158 1933.08333333333 39.3
160 159 1933.16666666667 44.5
161 160 1933.25 48.7
162 161 1933.33333333333 54.2
163 162 1933.41666666667 60.8
164 163 1933.5 65.5
165 164 1933.58333333333 64.9
166 165 1933.66666666667 60.1
167 166 1933.75 50.2
168 167 1933.83333333333 42.1
169 168 1933.91666666667 35.8
170 169 1934 39.4
171 170 1934.08333333333 38.2
172 171 1934.16666666667 40.4
173 172 1934.25 46.9
174 173 1934.33333333333 53.4
175 174 1934.41666666667 59.6
176 175 1934.5 66.5
177 176 1934.58333333333 60.4
178 177 1934.66666666667 59.2
179 178 1934.75 51.2
180 179 1934.83333333333 42.8
181 180 1934.91666666667 45.8
182 181 1935 40
183 182 1935.08333333333 42.6
184 183 1935.16666666667 43.5
185 184 1935.25 47.1
186 185 1935.33333333333 50
187 186 1935.41666666667 60.5
188 187 1935.5 64.6
189 188 1935.58333333333 64
190 189 1935.66666666667 56.8
191 190 1935.75 48.6
192 191 1935.83333333333 44.2
193 192 1935.91666666667 36.4
194 193 1936 37.3
195 194 1936.08333333333 35
196 195 1936.16666666667 44
197 196 1936.25 43.9
198 197 1936.33333333333 52.7
199 198 1936.41666666667 58.6
200 199 1936.5 60
201 200 1936.58333333333 61.1
202 201 1936.66666666667 58.1
203 202 1936.75 49.6
204 203 1936.83333333333 41.6
205 204 1936.91666666667 41.3
206 205 1937 40.8
207 206 1937.08333333333 41
208 207 1937.16666666667 38.4
209 208 1937.25 47.4
210 209 1937.33333333333 54.1
211 210 1937.41666666667 58.6
212 211 1937.5 61.4
213 212 1937.58333333333 61.8
214 213 1937.66666666667 56.3
215 214 1937.75 50.9
216 215 1937.83333333333 41.4
217 216 1937.91666666667 37.1
218 217 1938 42.1
219 218 1938.08333333333 41.2
220 219 1938.16666666667 47.3
221 220 1938.25 46.6
222 221 1938.33333333333 52.4
223 222 1938.41666666667 59
224 223 1938.5 59.6
225 224 1938.58333333333 60.4
226 225 1938.66666666667 57
227 226 1938.75 50.7
228 227 1938.83333333333 47.8
229 228 1938.91666666667 39.2
230 229 1939 39.4
231 230 1939.08333333333 40.9
232 231 1939.16666666667 42.4
233 232 1939.25 47.8
234 233 1939.33333333333 52.4
235 234 1939.41666666667 58
236 235 1939.5 60.7
237 236 1939.58333333333 61.8
238 237 1939.66666666667 58.2
239 238 1939.75 46.7
240 239 1939.83333333333 46.6
241 240 1939.91666666667 37.8

View File

@@ -0,0 +1,3 @@
library(readr)
df1 <- read_csv(file = "diamonds.csv")
View(df1)

View File

@@ -0,0 +1,87 @@
# Task 1
# b)
X <- 0:12
Y <- dgeom(X, p = 0.45)
plot(X, Y, type = "h", main = "Geometric distribution (p=0.45)", ylab = "P(X=k)")
points(X, Y, pch = 16)
# Task 2
# b)
X <- 0:30
Y <- dbinom(X, size = 30, prob = .6)
plot(X, Y, type = "h", main = "Binominal distribution (p=0.6)", ylab = "P(X=k)")
points(X, Y, pch = 16)
# Task 3
# 2)
X <- 0:40
Y <- dpois(X, lambda = 20)
plot(X, Y, type = "h", main = "Poisson distribution (lambda=20)", ylab = "P(X=k)")
points(X, Y, pch = 16)
# Task 4
library(readr)
data_set1 <- read_csv("data_set1.csv")
View(data_set1)
# 1) The name of the column is "Val".
# 2) There are 1029 rows.
# 3) Max = 109.379
max(data_set1)
# 4) Min = 4.193534
min(data_set1)
# 5) Mean = 50.49665
mean(data_set1$Val)
# 6) Median = 50.52415
median(data_set1$Val)
# 7) Variance = 218.7175
var(data_set1$Val)
# 8) Standard deviation = 14.7891
sd(data_set1$Val)
# Task 5
# 1)
library(readr)
data_set1 <- read_csv("data_set1.csv")
X <- 0:100
Y <- dnorm(X, mean = mean(data_set1$Val), sd = sd(data_set1$Val))
plot(X, Y, type = "l", ylim = c(0, 0.03), main = "Data set vs normal distribution")
# 2)
d <- density(data_set1$Val, bw = 3)
# 3)
points(d, col = "red", type = "l")
# 4)
abline(v = mean(data_set1$Val), col = "green")
# Task 6
# 4 variables most correlated with hp: mpg, cyl, disp, carb
cars <- mtcars
round(cor(cars), digits = 2)
# Task 7
# 1)
model <- lm(hp ~ cyl + disp + carb + mpg, data = mtcars)
# 2)
hp_hat <- predict(model)
# 3)
residuals <- mtcars$hp - hp_hat
# 4)
hpplot <- density(residuals)
plot(hpplot, main = "Density of residuals")
# 6)
summary(model)$r.squared # 0.8594845 - Correct and accurate
# Task 8
library(readr)
data_set2 <- read_csv("data_set2.csv")
X <- min(data_set2):max(data_set2)
Y <- dnorm(X, mean = mean(data_set2$Val), sd = sd(data_set2$Val))
plot(X, Y, type = "l", main = "Normal distribution of stick lengths")
d <- density(data_set2$Val, bw = 1)
points(d, col = "red", type = "l")
abline(v = mean(data_set2$Val), col = "green")
# The length of the sticks is not acceptable as the mean is much higher than the null hypothesis of µ = 30 and most values are not around 30.

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB