1.
Calculate Correlation using R
Code:
x <- c(10, 20, 30, 40, 50)
y <- c(15, 25, 35, 45, 60)
cor(x, y, method = "pearson")
Output:
[1] 0.9986254
2. Time Series Analysis using R
Code:
data("AirPassengers")
ts_data <- AirPassengers
summary(ts_data)
plot(ts_data)
decomposed <- decompose(ts_data)
plot(decomposed)
hw_model <- HoltWinters(ts_data)
plot(hw_model)
Output:
Output: Summary of dataset, Decomposition Plot, and Holt-Winters Plot
generated. (Visual Outputs)
3. Linear Regression using R
Code:
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 5, 4, 5)
model <- lm(y ~ x)
summary(model)
plot(x, y)
abline(model, col = "blue")
Output:
Call:
lm(formula = y ~ x)
Residuals:
1 2 3 4 5
-1.2 0.2 0.6 -0.8 1.2
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.2000 0.7483 2.940 0.0611 .
x 0.6000 0.2324 2.582 0.0806 .
(Visual: Scatter plot with regression line)
4. Scatter, Residual, Outliers, Leverage & Influential Points in R
Code:
x <- c(1, 2, 3, 4, 5, 6, 7)
y <- c(1, 2, 1.3, 3.75, 2.25, 5.5, 6.8)
model <- lm(y ~ x)
plot(x, y, main = "Scatter Plot with Regression Line")
abline(model, col = "blue")
plot(model, which = 1)
plot(model, which = 2)
plot(model, which = 4)
plot(model, which = 5)
Output:
Output: Multiple diagnostic plots for residuals, Q-Q, leverage and
influence (Visual Outputs)
5. Frequency Table in SPSS
Code:
Steps in SPSS:
1. Open dataset in SPSS.
2. Go to Analyze > Descriptive Statistics > Frequencies.
3. Select a categorical variable.
4. Click OK.
Output:
Output: Frequency table with counts, percentages, cumulative
percentages.
6. Gauss Elimination in Scilab
Code:
A = [2 1 -1; -3 -1 2; -2 1 2];
b = [8; -11; -3];
x = A\b;
disp(x)
Output:
Output:
2.
3.
-1.
6. Gauss Jordan in Scilab
Code:
A = [2 1 -1; -3 -1 2; -2 1 2];
b = [8; -11; -3];
Aug = [A b];
for i=1:3
Aug(i,:) = Aug(i,:) / Aug(i,i);
for j=1:3
if i <> j then
Aug(j,:) = Aug(j,:) - Aug(j,i)*Aug(i,:);
end
end
end
x = Aug(:,4);
disp(x)
Output:
Output:
2.
3.
-1.
6. Gauss Seidel in Scilab
Code:
A = [4 -1 0; -1 4 -1; 0 -1 3];
b = [15; 10; 10];
x = [0; 0; 0];
n = length(b);
tol = 1e-5;
for k = 1:100
x_old = x;
for i = 1:n
sum = b(i);
for j = 1:n
if i <> j then
sum = sum - A(i,j)*x(j);
end
end
x(i) = sum / A(i,i);
end
if norm(x - x_old, 2) < tol then
break
end
end
disp(x)
Output:
Output:
4.99998
4.99993
4.99998
7. Data Analysis using Titanic Dataset in R
Code:
titanic <-
read.csv("https://raw.githubusercontent.com/datasciencedojo/datasets/
master/titanic.csv")
str(titanic)
summary(titanic)
library(ggplot2)
ggplot(titanic, aes(x = Survived, fill = Sex)) + geom_bar(position =
"dodge")
table(titanic$Pclass, titanic$Survived)
Output:
Output:
- Structure of Titanic dataset.
- Bar chart of Survived vs Sex.
- Survival frequency table by Pclass.
8. Visualization of Air Quality Data in R
Code:
data("airquality")
summary(airquality)
plot(airquality$Ozone, type="l", col="blue", ylab="Ozone", xlab="Index")
plot(airquality$Temp, airquality$Ozone, main="Ozone vs Temperature",
xlab="Temperature", ylab="Ozone", col="red")
boxplot(airquality$Ozone, main="Boxplot of Ozone Levels")
Output:
Output:
- Line plot of Ozone values.
- Scatter plot of Temp vs Ozone.
- Boxplot showing Ozone distribution.