R Programming Notes
R Programming Notes
What is R?
Introduction to R
R is a language and environment for statistical computing and graphics. It is a GNU
project which is similar to the S language and environment which was developed at Bell
Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues.
R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical
tests, time-series analysis, classification, clustering) and graphical techniques, and is highly
extensible.
One of R’s strengths is the ease with which well-designed publication-quality plots can be
produced, including mathematical symbols and formulae where needed. R is available as Free
Software under the terms of the Free Software Foundation’s GNU General Public License in
source code form. It compiles and runs on a wide variety of UNIX platforms and similar
systems (including FreeBSD and Linux), Windows and MacOS.
The R environment
R is an integrated suite of software facilities for data manipulation, calculation and graphical
display. It includes
an effective data handling and storage facility,
a suite of operators for calculations on arrays, in particular matrices,
a large, coherent, integrated collection of intermediate tools for data analysis,
graphical facilities for data analysis and display either on-screen or on hardcopy, and
a well-developed, simple and effective programming language which includes
conditionals, loops, user-defined recursive functions and input and output facilities.
The term “environment” is intended to characterize it as a fully planned and coherent system,
rather than an incremental accretion of very specific and inflexible tools, as is frequently the
case with other data analysis software.
R, like S, is designed around a true computer language, and it allows users to add additional
functionality by defining new functions. Much of the system is itself written in the R dialect
of S, which makes it easy for users to follow the algorithmic choices made. For
computationally-intensive tasks, C, C++ and Fortran code can be linked and called at run
time. Advanced users can write C code to manipulate R objects directly.
Many users think of R as a statistics system. We prefer to think of it as an environment within
which statistical techniques are implemented. R can be extended (easily) via packages. There
R Comments
Comments are portions of a computer program that are used to describe a piece of code. For
example,
# declare variable
age = 24
# print variable
print(age)
Here, # declare variable and # print variable are two comments used in the code.
Comments have nothing to do with code logic. They do not get interpreted or compiled and
are completely ignored during the execution of the program.
Types of Comments in R
In general, all programming languages have the following types of comments:
single-line comments
multi-line comments
However, in R programming, there is no functionality for multi-line comments. Thus, you
can only write single-line comments in R.
1. R Single-Line Comments
You use the # symbol to create single-line comments in R. For example,
In the above example, we have printed the text Hello World to the screen. Here, just before
the print statement, we have included a single-line comment using the # symbol.
Note: You can also include a single-line comment in the same line after the code. For
example,
2. R Multi-Line Comments
As already mentioned, R does not have any syntax to create multi-line comments.
However, you can use consecutive single-line comments to create a multi-line comment in R.
For example,
print("Hello World")
Output
In the above code, we have used multiple consecutive single-line comments to create a multi-
line comment just before the print statement.
Purpose of Comments
As discussed above, R comments are used to just document pieces of code. This can help
others to understand the working of our code.
Here are a few purposes of commenting on an R code:
It increases readability of the program for users other than the developers.
Comments in R provide metadata of the code or the overall project.
Comments are generally used by programmers to ignore some pieces of code during testing.
They are used to write a simple pseudo-code of the program.
x = 13.8
Here, x is the variable where the data 13.8 is stored. Now, whenever we use x in our
program, we will get 13.8.
x = 13.8
# print variable
print(x)
Output
[1] 13.8
Note: In earlier versions of R programming, the period . was used to join words in a multi-
word variable such as first.name, my.age, etc. However, nowadays we mostly use _ for
multi-word variables For example, first_name, my_age, etc.
Types of R Variables
a = TRUE
print(a)
print(class(a))
Output
[1] TRUE
[1] "logical"
Here, we have declared the boolean variable a with the value TRUE. Boolean variables
belong to the logical class so class(a) returns "logical".
2. Integer Variables
It stores numeric data without any decimal values. For example,
A = 14L
print(A)
print(class(A))
Output
[1] 14
[1] "integer"
Here, L represents integer value. In R, integer variables belong to the integer class
so, class(a) returns "integer".
x = 13.4
print(x)
print(class(x))
Output
[1] 13.4
[1] "numeric"
Here, we have created a floating point variable named x. You can see that the floating point
variable belongs to the numeric class.
4. Character Variables
It stores a single character data. For example,
alphabet = "a"
print(alphabet)
print(class(alphabet))
Output
[1] "a"
[1] "character"
Here, we have created a character variable named alphabet . Since character variables belong
to the character class, class(alphabet) returns "character".
5. String Variables
It stores data that is composed of more than one character. We use double quotes to represent
string data. For example,
print(message)
print(class(message))
Output
Here, we have created a string variable named message. You can see that the string variable
also belongs to the character class.
print(message)
Output
In this program,
"Hello World!" - initial value of message
"Welcome to Programiz!" - changed value of message
Types of R Constants
In R, we have the following types of constants.
R Data Types
A variable can store different types of values such as numbers, characters etc. These different
types of data that we can use in our code are called data types. For example,
x <- 123L
Here, 123L is an integer data. So the data type of the variable x is integer.
We can verify this by printing the class of x.
x <- 123L
# print value of x
print(x)
# print type of x
print(class(x))
Output
[1] 123
[1] "integer"
print(bool1)
print(class(bool1))
print(bool2)
print(class(bool2))
Output
[1] TRUE
[1] "logical"
[1] FALSE
[1] "logical"
is_weekend <- F
print(class(is_weekend)) # "logical"
# real numbers
height <- 182
print(height)
print(class(height))
Output
[1] 63.5
[1] "numeric"
[1] 182
[1] "numeric"
Output
[1] "integer"
Here, 186L is an integer data. So we get "integer" when we print the class
of integer_variable.
Output
[1] "complex"
print(class(fruit))
print(class(my_char))
Output
[1] "character"
Here, both the variables - fruit and my_char - are of character data type.
print(raw_variable)
print(class(raw_variable))
print(char_variable)
print(class(char_variable))
Output
[1] 57 65 6c 63 6f 6d 65 20 74 6f 20 50 72 6f 67 72 61 6d 69 7a
[1] "raw"
[1] "Welcome to Programiz"
[1] "character"
In this program,
We have first used the charToRaw() function to convert the string "Welcome to
Programiz" to raw bytes.
This is why we get "raw" as output when we print the class of raw_variable.
This is why we get "character" as output when we print the class of char_variable.
R CONTROL FLOW
R if...else
In computer programming, the if statement allows us to create a decision making program.
A decision making program runs one block of code under a condition and another block of
code under different conditions. For example,
If age is greater than 18, allow the person to vote.
If age is not greater than 18, don't allow the person to vote.
R if Statement
The syntax of an if statement is:
if (test_expression) {
# body of if
}
Example: R if Statement
x <- 3
print("Outside if statement")
In the above program, the test condition x > 0 is true. Hence, the code inside parenthesis is
executed.
Note: If you want to learn more about test conditions, visit R Booleans Expression.
R if...else Statement
We can also use an optional else statement with an if statement. The syntax of an if...else
statement is:
if (test_expression) {
# body of if statement
} else {
# body of else statement
}
age <- 15
Output
In the above statement, we have created a variable named age. Here, the test expression is
age > 18
Since age is 16, the test expression is False. Hence, code inside the else statement is
executed.
If we change the variable to another number. Let's say 31.
age <- 31
x <- 12
Output
if(test_expression1) {
# code block 1
} else if (test_expression2){
# code block 2
} else {
# code block 3
}
Here,
If test_expression1 evaluates to True, the code block 1 is executed.
If test_expression1 evaluates to False, then test_expression2 is evaluated.
o If test_expression2 is True, code block 2 is executed.
o If test_expression2 is False, code block 3 is executed.
x <- 0
Output
In the above example, we have created a variable named x with the value 0. Here ,we have
two test expressions:
if (x > 0) - checks if x is greater than 0
else if (x < 0) - checks if x is less than 0
Here, both the test conditions are False. Hence, the statement inside the body of else is
executed.
x <- 20
# check if x is positive
if (x > 0) {
Output
In this program, the outer if...else block checks whether x is positive or negative. If x is
greater than 0, the code inside the outer if block is executed.
Otherwise, the code inside the outer else block is executed.
if (x > 0) {
... .. ...
} else {
... .. ...
}
The inner if...else block checks whether x is even or odd. If x is perfectly divisible by 2, the
code inside the inner if block is executed. Otherwise, the code inside the inner else block is
executed.
if (x %% 2 == 0) {
... .. ...
} else {
... .. ...
}
R LOOP
In programming, loops are used to repeat a block of code as long as the specified condition is
satisfied. Loops help you to save time, avoid repeatable blocks of code, and write cleaner
code.
In R, there are three types of loops:
while loops
for loops
repeat loops
R while Loop
while loops are used when you don't know the exact number of times a block of code is to be
repeated. The basic syntax of while loop in R is:
# calculate sum
sum = sum + number
# increment number by 1
number = number + 1
}
print(sum)
Output
[1] 55
Here, we have declared two variables: number and sum. The test_condition inside
the while statement is number <= 10.
number = 1
# increment number by 1
number = number + 1
# break if number is 6
if (number == 6) {
break
}
Output
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
In this program, we have used a break statement inside the while loop, which breaks the loop
as soon as the condition inside the if statement is evaluated to TRUE.
if (number == 6) {
break
}
number = 1
# increment number by 1
number = number + 1
}
Output
[1] 1
[1] 3
[1] 5
[1] 7
[1] 9
This program only prints the odd numbers in the range of 1 to 10. To do this, we have used
an if statement inside the while loop to check if number is divisible by 2.
Here,
if number is divisible by 2, then its value is simply incremented by 1 and the iteration is
skipped using the next statement.
R for Loop
A for loop is used to iterate over a list, vector or any other object of elements. The syntax
of for loop is:
Here, sequence is an object of elements and value takes in each of those elements. In each
iteration, the block of code is executed. For example,
numbers = c(1, 2, 3, 4, 5)
Output
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
In this program, we have used a for loop to iterate through a sequence of numbers
called numbers. In each iteration, the variable x stores the element from the sequence and the
block of code is executed.
# vector of numbers
num = c(2, 3, 12, 14, 5, 19, 23, 64)
# check if i is even
if (i %% 2 == 0) {
count = count + 1
}
}
print(count)
Output
[1] 4
In this program, we have used a for loop to count the number of even numbers in
the num vector. Here is how this program works:
We first initialized the count variable to 0. We use this variable to store the count of even
numbers in the num vector.
We then use a for loop to iterate through the num vector using the variable i.
for (i in num) {
# code block
Inside the for loop, we check if each element is divisible by 2 or not. If yes, then we
increment count by 1.
if (i %% 2 == 0) {
count = count + 1
# vector of numbers
numbers = c(2, 3, 12, 14, 5, 19, 23, 64)
print(i)
}
Output
[1] 2
[1] 3
[1] 12
[1] 14
Here, we have used an if statement inside the for loop. If the current element is equal to 5, we
break the loop using the break statement. After this, no iteration will be executed.
R repeat Loop
We use the R repeat loop to execute a code block multiple times. However, the repeat loop
doesn't have any condition to terminate the lYou can use the repeat loop in R to execute a
block of code multiple times. However, the repeat loop does not have any condition to
terminate the loop. You need to put an exit condition implicitly with a break statement inside
the loop.
The syntax of repeat loop is:
repeat {
# statements
Here, we have used the repeat keyword to create a repeat loop. It is different from
the for and while loop because it does not use a predefined condition to exit from the loop.
x=1
# Repeat loop
repeat {
print(x)
# Increment x by 1
x=x+1
Output
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
Here, we have used a repeat loop to print numbers from 1 to 5. We have used an if statement
to provide a breaking condition which breaks the loop if the value of x is greater than 4.
x=1
sum = 0
# Repeat loop
repeat {
# Calculate sum
sum = sum + x
# Print sum
print(sum)
# Increment x by 1
x=x+1
Output
[1] 1
[1] 3
[1] 6
[1] 10
.
.
.
In the above program, since we have not included any break statement with an exit condition,
the program prints the sum of numbers infinitely.
x=1
# Break if x = 4
if ( x == 4) {
break
}
# Skip if x == 2
if ( x == 2 ) {
# Increment x by 1 and skip
x=x+1
next
}
Output
[1] 1
[1] 3
Here, we have a repeat loop where we break the loop if x is equal to 4. We skip the iteration
where x becomes equal to 2.
R Functions
Introduction to R Functions
A function is just a block of code that you can call and run from any part of your program.
They are used to break our code in simple parts and avoid repeatable codes.
You can pass data into functions with the help of parameters and return some other data as a
result. You can use the function() reserve keyword to create a function in R. The syntax is:
Here, we have defined a function called power which takes two parameters - a and b. Inside
the function, we have included a code to print the value of a raised to the power b.
Output
Here, we have called the function with two arguments - 2 and 3. This will print the value
of 2 raised to the power 3 which is 8.
The arguments used in the actual function are called formal arguments. They are also called
parameters. The values passed to the function while calling the function are called actual
arguments.
Named Arguments
Output
Here, the result is the same irrespective of the order of arguments that you pass during the
function call.
You can also use a mix of named and unnamed arguments. For example,
Output
Output
Here, in the second call to power() function, we have only specified the b argument as a
named argument. In such a case, it uses the default value for a provided in the function
definition.
Return Values
You can use the return() keyword to return values from a function. For example,
Output
Here, instead of printing the result inside the function, we have returned a^b. When we call
the power() function with arguments, the result is returned which can be printed during the
call.
Elements of a Vector
Create a Vector in R
In R, we use the c() function to create a vector. For example,
print(employees)
In the above example, we have created a vector named languages. Each element of the vector
is associated with an integer number.
Vector Indexing in R
Here, we have used the vector index to access the vector elements
languages[1] - access the first element "Swift"
languages[3] - accesses the third element "R"
Note: In R, the vector index always starts with 1. Hence, the first element of a vector is
present at index 1, second element at index 2 and so on.
Output
Here, we have changed the vector element at index 2 from "Repeat" to "Sleep" by simply
assigning a new value.
Numeric Vector in R
Similar to strings, we use the c() function to create a numeric vector. For example,
print(numbers)
# Output: [1] 1 2 3 4 5
Here, we have used the C() function to create a vector of numeric sequence called numbers.
However, there is an efficient way to create a numeric sequence. We can use the : operator
instead of C().
Create a Sequence of Number in R
In R, we use the : operator to create a vector with numerical values in sequence. For
example,
print(numbers)
Output
[1] 1 2 3 4 5
Here, we have used the : operator to create the vector named numbers with numerical values
in sequence i.e. 1 to 5.
Mr. Gajendra kumar Ahirwar, SOIT RGPV BHOPAL Page 34
Repeat Vectors in R
In R, we use the rep() function to repeat elements of vectors. For example,
Output
In the above example, we have created a numeric vector with elements 2, 4, 6. Notice the
code,
rep(numbers, times=2)
Here,
numbers - vector whose elements to be repeated
times = 2 - repeat the vector two times
We can see that we have repeated the whole vector two times. However, we can also repeat
each element of the vector. For this we use the each parameter.
Let's see an example.
Output
In the above example, we have created a numeric vector with elements 2, 4, 6. Notice the
code,
rep(numbers, each = 2)
Output
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
Length of Vector in R
We can use the length() function to find the number of elements present inside the vector.
For example,
Output
Total Elements: 4
Here, we have used length() to find the length of the languages vector.
R Matrix
A matrix is a two-dimensional data structure where data are arranged into rows and columns.
For example,
Mr. Gajendra kumar Ahirwar, SOIT RGPV BHOPAL Page 36
R 3 * 3 Matrix
Here, the above matrix is 3 * 3 (pronounced "three by three") matrix because it has 3 rows
and 3 columns.
Create a Matrix in R
In R, we use the matrix() function to create a matrix.
The syntax of the matrix() function is
Here,
vector - the data items of same type
nrow - number of rows
ncol - number of columns
byrow (optional) - if TRUE, the matrix is filled row-wise. By default, the matrix is filled
column-wise.
Let's see an example,
# create a 2 by 3 matrix
matrix1 <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, ncol = 3, byrow = TRUE)
print(matrix1)
In the above example, we have used the matrix() function to create a matrix named matrix1.
Here, we have passed data items of integer type and used c() to combine data items together.
And nrow = 2 and ncol = 3 means the matrix has 2 rows and 3 columns.
Since we have passed byrow = TRUE, the data items in the matrix are filled row-wise. If we
didn't pass byrow argument as
matrix[n1, n2]
Here,
n1 - specifies the row position
n2 - specifies the column position
Let's see an example,
print(matrix1)
Output
[,1] [,2]
[1,] "Sabby" "Larry"
[2,] "Cathy" "Harry"
In the above example, we have created a 2 by 2 matrix named matrix1 with 4 string type
datas. Notice the use of index operator [],
matrix1[1, 2]
Here, [1, 2] specifies we are trying to access element present at 1st row, 2nd column
i.e. "Larry".
Access Entire Row or Column
In R, we can also access the entire row or column based on the value passed inside [].
[n, ] - returns the entire element of the nth row.
[ ,n] - returns the entire element of the nth column.
For example,
print(matrix1)
Output
[,1] [,2]
[1,] "Sabby" "Larry"
[2,] "Cathy" "Harry"
Here,
matrix1[1, ] - access entire elements at 1st row i.e. Sabby and Larry
matrix1[ ,2] - access entire elements at 2nd column i.e. Larry and Harry
Access More Than One Row or Column
We can access more than one row or column in R using the c() function.
[c(n1,n2), ] - returns the entire element of n1 and n2 row.
[ ,c(n1,n2)] - returns the entire element of n1 and n2 column.
For example,
# create 2 by 3 matrix
matrix1 <- matrix(c(10, 20, 30, 40, 50, 60), nrow = 2, ncol = 3)
print(matrix1)
Output
Here,
[c(1,3), ] - returns the entire element of 1st and 3rd row.
[ ,c(2,3)] - returns the entire element of 2nd and 3rd column.
matrix1[1,2] = 140
Here, the element present at 1st row, 2nd column is changed to 140.
Let's see an example,
# create 2 by 2 matrix
matrix1 <- matrix(c(1, 2, 3, 4), nrow = 2, ncol = 2)
Output
[,1] [,2]
[1,] 1 3
[2,] 2 4
[,1] [,2]
[1,] 1 5
[2,] 2 4
Output
Here, first we have used the cbind() function to combine the two
matrices: even_numbers and odd_numbers by column. And rbind() to combine two matrices
by row.
TRUE
FALSE
Here,
"Larry" is present in matrix1, so the method returns TRUE
"Kinsley" is not present in matrix1, so the method returns FALSE
R Data Frame
A data frame is a two-dimensional data structure which can store data in tabular format.
Data frames have rows and columns and each column can be a different vector. And different
vectors can be of different data types.
Before we learn about Data Frames, make sure you know about R vector.
Here,
first_col - a vector with values val1, val2, ... of same data type
second_col - another vector with values val1, val2, ... of same data type and so on
Let's see an example,
print(dataframe1)
In the above example, we have used the data.frame() function to create a data frame
named dataframe1. Notice the arguments passed inside data.frame(),
data.frame (
Name = c("Juan", "Alcaraz", "Simantha"),
Age = c(22, 15, 19),
Vote = c(TRUE, FALSE, TRUE)
)
Here, Name, Age, and Vote are column names for vectors of String, Numeric,
and Boolean type respectively.
And finally the datas represented in tabular format are printed.
Output
Name
1 Juan
2 Alcaraz
3 Simantha
[1] "Juan" "Alcaraz" "Simantha"
[1] "Juan" "Alcaraz" "Simantha"
In the above example, we have created a data frame named dataframe1 with three
columns Name, Age, Vote.
Here, we have used different operators to access Name column of dataframe1.
Accessing with [[ ]] or $ is similar. However, it differs for [ ], [ ] will return us a data frame
but the other two will reduce it into a vector and return a vector.
Output
Name Age
1 Juan 22
2 Alcaraz 15
3 Yiruma 46
4 Bach 89
Here, we have used the rbind() function to combine the two data
frames: dataframe1 and dataframe2 vertically.
Combine Horizontally Using cbind()
The cbind() function combines two or more data frames horizontally. For example,
Output
Output
Total Elements: 3
Here, we have used length() to find the total number of columns in dataframe1. Since there
are 3 columns, the length() function returns 3.
The CSV file above is a sample data of monthly air travel, in thousands of passengers,
for 1958-1960.
Now, let's try to read data from this CSV File using R's built-in functions.
Output
In the above example, we have read the airtravel.csv file that is available in our current
directory. Notice the code,
Here, read.csv() reads the csv file airtravel.csv and creates a dataframe which is stored in
the read_data variable.
Finally, the csv file is displayed using print().
Note: If the file is in some other location, we have to specify the path along with the file
name as: read.csv("D:/folder1/airtravel.csv") .
Output
Total Columns: 4
Total Rows: 12
In the above example, we have used the ncol() and nrow() function to find the total number of
columns and rows in the airtravel.csv file.
Here,
ncol(read_data) - returns total number of columns i.e. 4
Output
[1] 390
[1] 505
Here, we have used the min() and max() function to find the minimum and maximum value
of the 1960 and 1958 column of the airtravel.csv file respectively.
min(read_data$1960) - returns the minimum value from the 1960 column i.e. 390
max(read_data$1958) - returns the maximum value from the 1958 column i.e. 505
Output
In the above example, we have specified a certain condition inside the subset() function to
extract data from a CSV file.
Here, subset() creates a subset of airtravel.csv with data column 1958 having data greater
than 400 and stored it in the sub_data data frame.
Since column 1958 has data greater than 400 in 6th, 7th, 8th, and 9th row, only these rows
are displayed.
In the above example, we have used the write.csv() function to export a data frame
named dataframe1 to a CSV file. Notice the arguments passed inside write.csv(),
write.csv(dataframe1, "file1.csv")
write.csv(dataframe1, "file1.csv",
quote = FALSE
)
LINEAR MODEL IN R
A linear model is used to predict the value of an unknown variable based on independent
variables. It is mostly used for finding out the relationship between variables and
forecasting. The lm() function is used to fit linear models to data frames in the R
Language. It can be used to carry out regression, single stratum analysis of variance, and
analysis of covariance to predict the value corresponding to data that is not in the data
frame. These are very helpful in predicting the price of real estate, weather forecasting,
etc.
To fit a linear model in the R Language by using the lm() function, We first use
data.frame() function to create a sample data frame that contains values that have to be
fitted on a linear model using regression function. Then we use the lm() function to fit a
certain function to a given data frame.
Syntax:
lm( fitting_formula, dataframe )
Parameter:
fitting_formula: determines the formula for the linear model.
dataframe: determines the name of the data frame that contains the data.
Then, we can use the summary() function to view the summary of the linear model. The
summary() function interprets the most important statistical values for the analysis of the
linear model.
Syntax:
summary( linear_model )
The summary contains the following key information:
Residual Standard Error: determines the standard deviation of the error where the
square root of variance subtracts n minus 1 + # of variables involved instead of
dividing by n-1.
Multiple R-Squared: determines how well your model fits the data.
Adjusted R-Squared: normalizes Multiple R-Squared by taking into account how
many samples you have and how many variables you’re using.
F-Statistic: is a “global” test that checks if at least one of your coefficients is non-
zero.
Example: Example to show usage of lm() function.
R
y= c(1,5,8,15,26))
summary(linear_model)
Output:
Call:
lm(formula = y ~ x^2, data = df)
Residuals:
1 2 3 4 5
2.000e+00 5.329e-15 -3.000e+00 -2.000e+00 3.000e+00
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -7.0000 3.0876 -2.267 0.10821
x 6.0000 0.9309 6.445 0.00757 **
—
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.944 on 3 degrees of freedom
Multiple R-squared: 0.9326, Adjusted R-squared: 0.9102
F-statistic: 41.54 on 1 and 3 DF, p-value: 0.007575
Diagnostic Plots
The diagnostic plots help us to view the relationship between different statistical values of
the model. It helps us in analyzing the extent of outliers and the efficiency of the fitted
model. To view diagnostic plots of a linear model, we use the plot() function in the R
Language.
R
y= c(1,5,8,15,26))
plot(linear_model)
Output:
R
y= c(1,5,8,15,26))
abline( linear_model)
Output: