0% found this document useful (0 votes)
20 views

Student Motivation On Performance-1

Uploaded by

Justine Mwenda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Student Motivation On Performance-1

Uploaded by

Justine Mwenda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Student Motivation on Performance

June 4, 2024

[1]: import pandas as pd


import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from scipy import stats
import statsmodels.api as sm
from sklearn.decomposition import FactorAnalysis
from sklearn.cluster import KMeans
from sklearn.linear_model import LinearRegression
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline

1 Load data into a pandas DataFrame


[2]: df = pd.read_csv('Student.csv')

1.1 Data processin and cleaning


[3]: # Replace gender values
df['Gender'] = df['Gender'].map({'M': 1, 'F': 0})

[4]: # Display the first few rows of the DataFrame


print(df.head())

Age Gender Intrinsic Institution suport Promotion appraisal \


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

Recommendation Satisfaction Workplace Work relation Security \


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

1
4 3 2 3 3 3

Cultural belief Hostile environment Student motivation \


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

Student engagement motivation Student engagement demotivation \


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

Performance motivating environment Performance demotivating environment


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

2 Descriptive statistics
[5]: print(df.describe())

Age Gender Intrinsic Institution suport \


count 20.000000 20.000000 20.000000 20.00000
mean 1.700000 0.500000 3.500000 3.65000
std 0.864505 0.512989 0.760886 0.74516
min 1.000000 0.000000 1.000000 1.00000
25% 1.000000 0.000000 3.000000 3.75000
50% 1.500000 0.500000 4.000000 4.00000
75% 2.000000 1.000000 4.000000 4.00000
max 4.000000 1.000000 4.000000 4.00000

Promotion appraisal Recommendation Satisfaction Workplace \


count 20.00000 20.000000 20.00000 20.000000
mean 3.35000 3.700000 2.85000 3.600000
std 0.74516 0.470162 0.67082 0.502625
min 1.00000 3.000000 2.00000 3.000000
25% 3.00000 3.000000 2.00000 3.000000
50% 3.00000 4.000000 3.00000 4.000000
75% 4.00000 4.000000 3.00000 4.000000
max 4.00000 4.000000 4.00000 4.000000

2
Work relation Security Cultural belief Hostile environment \
count 20.000000 20.000000 20.000000 20.000000
mean 3.300000 3.150000 2.850000 2.650000
std 0.656947 0.366348 0.812728 0.587143
min 2.000000 3.000000 2.000000 1.000000
25% 3.000000 3.000000 2.000000 2.000000
50% 3.000000 3.000000 3.000000 3.000000
75% 4.000000 3.000000 3.250000 3.000000
max 4.000000 4.000000 4.000000 3.000000

Student motivation Student engagement motivation \


count 20.000000 20.000000
mean 3.650000 2.700000
std 0.587143 0.470162
min 2.000000 2.000000
25% 3.000000 2.000000
50% 4.000000 3.000000
75% 4.000000 3.000000
max 4.000000 3.000000

Student engagement demotivation Performance motivating environment \


count 20.000000 20.000000
mean 2.650000 3.550000
std 0.812728 0.825578
min 1.000000 1.000000
25% 2.000000 3.000000
50% 3.000000 4.000000
75% 3.000000 4.000000
max 4.000000 4.000000

Performance demotivating environment


count 20.000000
mean 1.900000
std 0.640723
min 1.000000
25% 1.750000
50% 2.000000
75% 2.000000
max 3.000000

[ ]:

3 Compute the correlation matrix


[6]: correlation_matrix = df.corr()

3
[7]: # Visualize the correlation matrix
plt.figure(figsize=(10, 8))
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', linewidths=0.5)
plt.title('Correlation Matrix')
plt.show()

[ ]:

[ ]:

4
4 Perform Factor Analysis
[8]: # Perform Factor Analysis
fa = FactorAnalysis(n_components=4)
factors = fa.fit_transform(df)

# Add factor scores to DataFrame


df['Factor1'] = factors[:, 0]
df['Factor2'] = factors[:, 1]

print(df[['Factor1', 'Factor2']].head())

Factor1 Factor2
0 0.536643 -0.618086
1 -0.600141 0.917624
2 -0.610987 0.679136
3 -0.492215 2.242386
4 0.887281 2.003611

[ ]:

[ ]:

5 Cluster Analysis
[9]: # Perform K-means clustering
kmeans = KMeans(n_clusters=10)
clusters = kmeans.fit_predict(df)

# Add cluster labels to DataFrame


df['Cluster'] = clusters

print(df[['Cluster']].head())

Cluster
0 9
1 7
2 2
3 8
4 5

[ ]:

[ ]:

5
6 Regression Analysis
[9]: # Define the independent variables (X) and dependent variable (y)
X = df[['Intrinsic', 'Institution suport', 'Promotion appraisal', 'Performance␣
↪motivating environment', 'Performance demotivating environment', 'Cultural␣

↪belief', 'Promotion appraisal']]

y = df['Student motivation']

# Add a constant term to the independent variables matrix


X = sm.add_constant(X)

# Fit the regression model


model = sm.OLS(y, X).fit()

# Print the summary of the regression model


print(model.summary())

OLS Regression Results


==============================================================================
Dep. Variable: Student motivation R-squared: 0.666
Model: OLS Adj. R-squared: 0.512
Method: Least Squares F-statistic: 4.327
Date: Tue, 04 Jun 2024 Prob (F-statistic): 0.0129
Time: 13:53:43 Log-Likelihood: -6.2396
No. Observations: 20 AIC: 26.48
Df Residuals: 13 BIC: 33.45
Df Model: 6
Covariance Type: nonrobust
================================================================================
========================
coef std err t P>|t|
[0.025 0.975]
--------------------------------------------------------------------------------
------------------------
const 2.5000 0.785 3.184 0.007
0.803 4.196
Intrinsic 0.7474 0.228 3.274 0.006
0.254 1.241
Institution suport -0.3309 0.287 -1.151 0.270
-0.952 0.290
Promotion appraisal -0.0171 0.127 -0.135 0.895
-0.291 0.257
Performance motivating environment 0.1908 0.152 1.258 0.230
-0.137 0.518
Performance demotivating environment -0.1630 0.177 -0.919 0.375
-0.546 0.220
Cultural belief -0.1792 0.156 -1.146 0.273
-0.517 0.159

6
Promotion appraisal -0.0171 0.127 -0.135 0.895
-0.291 0.257
==============================================================================
Omnibus: 2.119 Durbin-Watson: 1.906
Prob(Omnibus): 0.347 Jarque-Bera (JB): 0.838
Skew: -0.457 Prob(JB): 0.658
Kurtosis: 3.414 Cond. No. 1.89e+17
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly
specified.
[2] The smallest eigenvalue is 4.19e-32. This might indicate that there are
strong multicollinearity problems or that the design matrix is singular.

[ ]:

[ ]:

7 ANOVA
[10]: # Perform ANOVA
f_val, p_val = stats.f_oneway(df['Student motivation'][df['Performance␣
↪motivating environment'] == 1],

df['Student motivation'][df['Performance␣
↪motivating environment'] == 2],

df['Student motivation'][df['Performance␣
↪motivating environment'] == 3],

df['Student motivation'][df['Performance␣
↪motivating environment'] == 4])

print(f"ANOVA results: F={f_val}, p={p_val}")

ANOVA results: F=4.07179487179487, p=0.025100230259332102

8 Barchart
[16]: # Bar chart for the 'Intrinsic' variable
plt.figure(figsize=(10, 6))
df['Intrinsic'].value_counts().sort_index().plot(kind='bar', color='skyblue')
plt.title('Distribution of Intrinsic Factor Scores')
plt.xlabel('Intrinsic Factor Scores')
plt.ylabel('Frequency')
plt.xticks(rotation=0)
plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.show()

7
[17]: # Bar chart for the Teacher Salary satisfaction
plt.figure(figsize=(10, 6))
df['Satisfaction'].value_counts().sort_index().plot(kind='bar', color='skyblue')
plt.title('Distribution of Teacher Salary satisfaction Scores')
plt.xlabel('Teacher Salary satisfaction')
plt.ylabel('Frequency')
plt.xticks(rotation=0)
plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.show()

8
[18]: # Bar chart for the Student Performance motivating environment
plt.figure(figsize=(10, 6))
df['Performance motivating environment'].value_counts().sort_index().
↪plot(kind='bar', color='skyblue')

plt.title('Distribution of Student Performance motivating environment Scores')


plt.xlabel('Student Performance motivating environment')
plt.ylabel('Frequency')
plt.xticks(rotation=0)
plt.grid(axis='y', linestyle='--', alpha=0.7)
plt.show()

9
9 Pie Chart
[20]: # Create a pie chart for the 'Gender' variable
gender_counts = df['Gender'].value_counts()
plt.figure(figsize=(8, 8))
plt.pie(gender_counts, labels=['Male', 'Female'], autopct='%1.1f%%',␣
↪startangle=140, colors=['lightblue', 'lightcoral'])

plt.title('Gender Distribution')
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()

10
[22]: # Create a pie chart for the 'Age' variable
age_mapping = {1: '20-30', 2: '31-40', 3: '41-50', 4: '51-60'}
df['Age Group'] = df['Age'].map(age_mapping)

age_counts = df['Age Group'].value_counts()


plt.figure(figsize=(8, 8))
plt.pie(age_counts, labels=age_counts.index, autopct='%1.1f%%', startangle=140,␣
↪colors=plt.cm.Paired(range(len(age_counts))))

plt.title('Age Distribution of Teaching Staff')


plt.axis('equal')
plt.show()

11
[ ]:

12

You might also like