Create Regression Model in R with Interaction Between Two Variables

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:45:01

482 Views

The easiest way to create a regression model with interactions is inputting the variables with multiplication sign that is * but this will create many other combinations that are of higher order. If we want to create the interaction of two variables combinations then power operator can be used as shown in the below examples.Example1 Live Demox1

Difference Between Ordered and Unordered Factors in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:38:37

1K+ Views

To understand the difference ordered factors and unordered factors, it is better to understand them by creating the factor vectors by using ordered argument with TRUE and FALSE options. For example, if we have a vector x then it can be ordered or unordered as factor(x,ordered=TRUE) and factor(x,ordered=FALSE).Example1 Live Demox1

Combine Array of Vectors in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:36:46

790 Views

To combine array of vectors we can use rbind function. For example, if we have multiple vectors say x, y, z of same size or different sizes but the total number of elements are even then we can use rbind(x,y,z) to combine those vectors. Check out the examples to understand how it works.Example1 Live Demox1

Convert Factor Levels to Character in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:28:19

5K+ Views

To convert factor levels into character then we can use as.character function by accessing the column of the data frame that contain factor values. For example, if we have a data frame df which contains a factor column named as Gender then this column can be converted into character column as as.character(df$Gender).Example Live DemoConsider the below data frame −set.seed(121) x1

Create Boxplot in Base R Without Axes Labels

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:25:48

2K+ Views

The boxplot can be created by using boxplot function in base R but the Y−axis labels are generated based on the vector we pass through the function. If we want to remove the axis labels then axes = FALSE argument can be used. For example, if we have a vector x then the boxplot for x without axes labels can be created by using boxplot(x,axes=FALSE).Example Live DemoConsider the below vector x and creating boxplot −set.seed(777) x

Find P-Value for Correlation Coefficient in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:22:12

11K+ Views

The t test is used to find the p−value for the correlation coefficient and on the basis of that we decide whether there exists a statistically significant relationship between two variables or not. In R, we can perform this test by using function cor.test. For example, if we have a vector x and y then we can find the p−value using cor.test(x,y).Example1 Live Demoset.seed(444) x1

Create Boxplot for Multiple Categories with Long Names in Base R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:20:45

237 Views

In base R, we use boxplot function to create the boxplots but if we have categorical vector and the corresponding numerical vector then the boxplot can be easily created. For this purpose, we should save those vectors in a data frame and use the $ operator and las = 2 argument to create the boxplot as shown in the below example.ExampleConsider the below vectors:Countries Rate

Generate Power Sequence of Two in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:15:49

6K+ Views

In R, for the calculation of power we can simply use power operator ^ and this will be also used in case of generating a power sequence. For example, if we want to generate a power sequence from 1 to 5 of 2 then we can use the code 2^(1:5) this will result 2 4 8 16 32.Example Live Demo2^(0:2)Output[1] 1 2 4Example Live Demo2^(0:10)Output[1] 1 2 4 8 16 32 64 128 256 512 1024 Example Live Demo2^(0:50)Output[1] 1.000000e+00 2.000000e+00 4.000000e+00 8.000000e+00 1.600000e+01 [6] 3.200000e+01 6.400000e+01 1.280000e+02 2.560000e+02 5.120000e+02 [11] 1.024000e+03 2.048000e+03 4.096000e+03 8.192000e+03 1.638400e+04 [16] 3.276800e+04 6.553600e+04 1.310720e+05 2.621440e+05 5.242880e+05 [21] ... Read More

Create Point Chart with Empty Points Using ggplot2 in R

Nizamuddin Siddiqui
Updated on 17-Oct-2020 12:09:22

3K+ Views

The point chart can be created by using geom_point function and if we want to create a point chart for single vector then we should pass the vector in both the places inside aes function. Also, by default the points are complete black circles and if we want to change the points to empty points then shape argument can be used.ExampleConsider the below data frame − Live Demoset.seed(171) x

Sum Number Digits in JavaScript

AmitDiwan
Updated on 17-Oct-2020 11:48:08

146 Views

We are required to write a JavaScript function that takes in an positive integer and returns its additive persistence.The additive persistence of an integer, say n, is the number of times we have to replace the number with the sum of its digits until the number becomes a single digit integer.For example: If the number is −1679583Then, 1 + 6 + 7 + 9 + 5 + 8 + 3 = 39 // 1 Pass 3 + 9 = 12 // 2 Pass 1 + 2 = 3 // 3 PassTherefore, the output should be 3.ExampleThe code for this will ... Read More

Advertisements