Tuesday, November 12, 2024

Day 2: 30-days to learn rgl, plotly, and gganimate - Explore plotly customizations: add labels, hover effects, adjust colors, and practice layout modifications

 


Step 1: Set Up the Basic Plot

We’ll start by creating a simple scatter plot that we’ll customize throughout this tutorial.

1.     Create a Sample Dataset:

# Sample data
x <- c(1, 2, 3, 4, 5)
y <- c(10, 15, 13, 17, 20)
labels <- c("A", "B", "C", "D", "E")

2.     Generate the Basic Scatter Plot:

library(plotly)
 
# Basic scatter plot
plot <- plot_ly(x = ~x, y = ~y, type = 'scatter', mode = 'markers')
plot

Step 2: Add Labels

You can add custom labels for each point to provide additional context.

1.     Add Labels as Text:

plot <- plot_ly(x = ~x, y = ~y, text = ~labels, type = 'scatter', mode = 'markers+text') %>%
  layout(title = "Scatter Plot with Labels",
         xaxis = list(title = "X Axis"),
         yaxis = list(title = "Y Axis"))
plot
    • Explanation:
      • text = ~labels: Adds text labels from the labels variable.
      • mode = 'markers+text': Displays both markers and text.

2.     Adjust Text Position:

plot <- plot %>%
  layout(title = "Scatter Plot with Custom Label Positions") %>%
  style(textposition = 'top right')  # Try 'top left', 'bottom right', etc.
plot

Step 3: Add and Customize Hover Effects

Hover effects can be customized to display more detailed information.

1.     Customize Hover Text:

plot <- plot_ly(x = ~x, y = ~y, text = ~paste("Point:", labels, "<br>X:", x, "<br>Y:", y),
                hoverinfo = 'text', type = 'scatter', mode = 'markers') %>%
  layout(title = "Scatter Plot with Customized Hover Text")
plot
    • Explanation:
      • hoverinfo = 'text': Specifies that hover text should come from the text argument.
      • paste() function with <br>: Adds HTML line breaks to format the hover text neatly.

Step 4: Adjust Colors

Colors can make plots visually appealing and help convey information.

1.     Change Marker Colors:

plot <- plot_ly(x = ~x, y = ~y, text = ~labels, type = 'scatter', mode = 'markers',
                marker = list(color = 'blue', size = 10)) %>%
  layout(title = "Scatter Plot with Custom Marker Color")
plot


2.     Add Conditional Colors:

# Set colors based on y values
colors <- c("red", "green", "blue", "orange", "purple")
 
plot <- plot_ly(x = ~x, y = ~y, text = ~labels, type = 'scatter', mode = 'markers',
                marker = list(color = colors, size = 10)) %>%
  layout(title = "Scatter Plot with Conditional Colors")
plot

3.     Use a Color Gradient:

plot <- plot_ly(x = ~x, y = ~y, text = ~labels, type = 'scatter', mode = 'markers',
                marker = list(color = ~y, colorscale = 'Viridis', size = 10)) %>%
  layout(title = "Scatter Plot with Gradient Colors")
plot

Step 5: Customize Layout

plotly offers extensive layout options to adjust axes, titles, legends, and background.

1.     Modify Title and Axis Titles:

plot <- plot %>%
  layout(title = list(text = "Customized Scatter Plot", font = list(size = 20, color = "darkblue")),
         xaxis = list(title = "Custom X Axis", titlefont = list(size = 15, color = "darkred")),
         yaxis = list(title = "Custom Y Axis", titlefont = list(size = 15, color = "darkgreen")))
plot

2.     Customize Legend:

# Adding a legend and customizing its position and appearance
plot <- plot %>%
  layout(showlegend = TRUE, legend = list(x = 1, y = 1, font = list(size = 10, color = "black")))
plot

3.     Change Background Color:

plot <- plot %>%
  layout(plot_bgcolor = 'lightgrey',  # Background color of the plot area
         paper_bgcolor = 'lavender')  # Background color of the paper
plot



Step 6: Combine All Customizations

Let’s put together everything we learned to create a fully customized scatter plot.

plot <- plot_ly(x = ~x, y = ~y, text = ~paste("Label:", labels, "<br>X:", x, "<br>Y:", y),
                hoverinfo = 'text', type = 'scatter', mode = 'markers+text',
                marker = list(color = ~y, colorscale = 'Viridis', size = 15)) %>%
  layout(title = list(text = "Fully Customized Scatter Plot", font = list(size = 22, color = "darkblue")),
         xaxis = list(title = "Custom X Axis", titlefont = list(size = 15, color = "darkred")),
         yaxis = list(title = "Custom Y Axis", titlefont = list(size = 15, color = "darkgreen")),
         plot_bgcolor = 'lightgrey',
         paper_bgcolor = 'lavender',
         legend = list(x = 1, y = 1, font = list(size = 10, color = "black")))
 
plot

Summary

Today, you:

  • Added text labels and customized their position.
  • Created hover text with detailed information and used HTML for formatting.
  • Customized colors, including conditional colors and gradients.
  • Modified layout elements such as titles, axis labels, background color, and legend position.

Next, you’ll practice 3D plotting and explore deeper interactions to make your plots even more dynamic.


Monday, November 11, 2024

Day 1 - 30 days R learning plan for gganimate, plotly, and rgl, and their combination

 


Here’s a step-by-step tutorial for Day 1 to get you started with plotly in R. This guide will walk you through the installation process and teach you how to create basic interactive plots like scatter, bar, and line charts.


Step 1: Install and Load plotly

1.     Open RStudio (or any R environment): Make sure you have an R environment ready to work with.

2.     Install plotly: If you haven’t installed plotly yet, use the following code:

install.packages("plotly")

3.     Load plotly: Load the library so that you can use it in your session.

library(plotly)

Step 2: Create Basic Interactive Plots

A. Scatter Plot

1.     Create Sample Data: For the scatter plot, let’s create a simple dataset to plot.

# Sample data
x <- c(1, 2, 3, 4, 5)
y <- c(10, 15, 13, 17, 20)

2.     Create a Scatter Plot with plot_ly(): Use plot_ly() to create an interactive scatter plot.

scatter_plot <- plot_ly(x = ~x, y = ~y, type = 'scatter', mode = 'markers')
scatter_plot
    • Explanation:
      • x = ~x and y = ~y: Define the x and y coordinates for the points.
      • type = 'scatter': Specifies a scatter plot.
      • mode = 'markers': Displays only markers (you can also try 'lines+markers').

B. Bar Chart

1.     Create Sample Data for a Bar Chart:

categories <- c("A", "B", "C", "D")
values <- c(20, 14, 23, 17)

2.     Create a Bar Chart:

bar_chart <- plot_ly(x = ~categories, y = ~values, type = 'bar')
bar_chart
    • Explanation:
      • x = ~categories: Defines the x-axis labels.
      • y = ~values: Defines the values for each bar.
      • type = 'bar': Specifies a bar chart.

C. Line Chart

1.     Create Data for a Line Chart:

time <- c(1, 2, 3, 4, 5)
values <- c(3, 7, 9, 6, 10)

2.     Create a Line Chart:

line_chart <- plot_ly(x = ~time, y = ~values, type = 'scatter', mode = 'lines')
line_chart
    • Explanation:
      • type = 'scatter' with mode = 'lines': This combination creates a line plot.
      • x = ~time and y = ~values: Define the x and y coordinates for the line.

Step 3: Customize Your Plots

You can customize colors, add titles, and adjust axis labels for each plot.

1.     Add Titles and Labels:

# Scatter Plot with Labels
scatter_plot <- scatter_plot %>%
  layout(title = "Interactive Scatter Plot",
         xaxis = list(title = "X Axis"),
         yaxis = list(title = "Y Axis"))
 
# Bar Chart with Labels
bar_chart <- bar_chart %>%
  layout(title = "Interactive Bar Chart",
         xaxis = list(title = "Categories"),
         yaxis = list(title = "Values"))
 
# Line Chart with Labels
line_chart <- line_chart %>%
  layout(title = "Interactive Line Chart",
         xaxis = list(title = "Time"),
         yaxis = list(title = "Values"))

2.     View Customized Plots: Display each plot with the customized labels.

scatter_plot
bar_chart
line_chart

Step 4: Explore Interactivity

Hover over the data points on each plot to see interactive information, and try zooming and panning. plotly provides built-in interactivity, including tooltips and customizable actions.


Saturday, November 9, 2024

Overseas Pakistani may need to invest in Pakistan

(Source: Pixabay)

It is usually said by Pakistani people living abroad that they are not investing in Pakistan, as its situation is not stable. However, it has to be considered that only about 10% people living abroad can afford property in those countries. Many people have not much money to purchase property abroad. Therefore, it needs for them to purchase some property in Pakistan. Usually, people living abroad can purchase plots, flats, or shops in about 200 or 300 pounds saving per month. In the sale and purchase of property, people have to consider that it has certain cycles of ups and downs of payments. For instance, in almost every politician’s time, property have gone up and then down. In Dubai, where there is no obvious politics, prices of plots go up and down. Nevertheless, overseas Pakistanis can purchase property in lower monthly payments as compared to the past.

Source:

Property Naama - Overseas Pakistan Can’t Afford To Buy Property In Abroad? Why To Invest In Pakistan? Reason 2024 - https://www.youtube.com/watch?v=l9z6EXHmLf4


Friday, November 8, 2024

Factors in the decline of prices in DHA Phase 5, Rawalpindi/Islamabad

(Source: https://www.dhai-r.com.pk/phase-detail/phase-v)

DHA Expressway is present in DHA Phase 5. This phase already has several important buildings, including Novacare healthcare, Caltex petrol pump, McDonald’s, and DHA’s main building. Considering this development, many private agencies have also started their developments in this area. Earlier this year, an 8 marla plot was available only at about 10 crores, and even 4 marla plots have the price in the range above 4 crores. Now, the prices for 8 marla plots have gone down to about 9 crores to 9.5 crores, and 4 marla plots are now at about 3.65 crores.

Considering the reasons behind the decline in prices, even with the presence of all different types of positive factors, it can be noted that after budget, commercial plots got Federal Excise Duty (FED). So, when someone gets a plot in DHA, they have to pay not only Advance Tax but also FED and DHA Membership Fee. These extra burdens of taxes result in the decline in prices. Another reason is the presence of businessway where people have started showing interest leading to a decline in prices near DHA expressway. Then, the development of Central Commercial, where banks, parks, and plaza with rents can be found. These three factors can be considered important in the decline in prices. However, the completion of DHA headoffice in phase 5 (by December 2025) and the completion of other famous areas (already mentioned), such as Novacare hospital (by 2026 or 2027) can eventually increase the prices of plots.

Source:

Property Gupshup - 😱BIG DROP in price on DHA Expressway | Property Gupshup - https://www.youtube.com/watch?v=UKd0jHytuco


Thursday, November 7, 2024

Profitability in Capital Smart City, near Islamabad, Pakistan

 

(Source: https://www.smartcitypk.com/overseas-launch)

Capital Smart City is one of the housing societies in Islamabad, Pakistan. It is said that plots in Capital Smart City are experiencing profits. People who got plots in Prime One also experience further benefits of achieving their plots and make their homes. It is also said that people from Villa Apartment are also experiencing profits. In this area, people having 5 marla plots can get about 35 lacs to 40 lacs of profit. Considering people with 10 marla plots in this area, who acquired plots in about 1.35 crores to 1.40 crores, now may get about 3 crores for their plots within 4 years. People from Executives also experience profits. On the other hand, people with balloted plots in Executives, and now shifting to other areas, may experience loss. However, chances are high that they would get profit. Eventually, people with plots or balloted plots in Overseas may get good profits within 5 years of possession. This is because this area gets such a way that comes while moving from Motorway to DHA Gandhara, Faisal Town, and Blue World City. So, Overseas Central is one of the most important and beneficial area in terms of property profits.

Source:

Tayyab Sethi Podcast - Capital Smart City Overseas Block Investment | Whic Block Is Most Profitable For Investment - https://www.youtube.com/watch?v=0YUgPC0rgZM


Wednesday, November 6, 2024

Taxes on property related businesses are high

(Source: Pixabay)

FBR in Pakistan is posing some taxes on property business. In the Top City Housing Society, the transfer fees of 5 marla plots is about 2.67 lacs for the buyer and 1.56 lacs for the owner of the property. In this housing society, the rate of the plot is about 70 lacs. FBR is also increasing the DC rate. For instance, if previously, DC rate of a 70 lac rupees plot was 35 lacs, it would increase to about 50 lacs to 55 lacs. In this case, property teams and Islamabad Chamber of Commerce have to arrange meetings with FBR, as many people in FBR may not have this much experience about property. For instance, people with salaries may not be able to understand the property-related business.

Source:

Gondal Group of Marketing Islamabad - FBR New Taxes on Real Estate Sector, FBR Tax 2024-25, Property Sale-Purchase TAX Islamabad Pakistan - https://www.youtube.com/watch?v=WxG_E2fCJmc&t=19s


Monday, November 4, 2024

Some reasons regarding why people experienced losses in real estate

 

(Source: Pixabay)

The real estate business found a novel trend during 2016 to 2017. It started integrating social media. After that time, many clients started looking social media. However, mostly people have experienced losses after this. One of the main reasons for losses is that people have not done investigation on their own and often started investing in Files in societies.

Another point to be considered is that on installment plan, you may not find property in Islamabad. You may have to go outside of Islamabad in new housing societies. Usually, these installment plans are associated with long term investments that may range from 8 years to 10 years, but people may start getting panicked within 3 years that why I am not getting profit. One thing, in case of fraud, you may note that the housing society has not done any progress for the last 2 to 3 years, and still calling clients to get plots. The housing societies that are constantly doing something on ground for clients can be considered authentic and can be asked for payments on installments.

Source:

Gondal Group of Marketing Islamabad - The Main Reason for Losses in Property Investment | How to Prevent Property Losses And Frauds - https://www.youtube.com/watch?v=4h6bln9ewwA


Sunday, November 3, 2024

Briefly about Taj Residencia, Islamabad

 

(Source: https://tajresidencia.com/)

Taj Residencia in Islamabad is the project of Sardar Group, who also have the ownership of Centaurus Mall in Islamabad. This society has also announced the building of second Centaurus Mall. In this area, villas have already been launched, the prices of which start from 1.65 crores for 5 marla villas. In this area, cash plots are also available. On installments, 5 marla may start from 35 lacs, but mostly cash plots are available.

Source:

Octa Plus Marketing  - Taj Residencia Islamabad Latest Site Visit |Possession Plots , House & Villas | Development Updates  - https://www.youtube.com/watch?v=W9K79xlUu-Q


Friday, November 1, 2024

Prices of 5 marla plots in some of the societies near Islamabad, Pakistan

 


In the case of real estate, it has to be noted that it is going well at this time. During the year 2024, prices have already started moving towards betterment, as the country’s condition is improving. Nevertheless, considering the investment for short-term, it can be considered that you may invest in any housing society available to you. In the case of long-term investment, in which you may need to invest through installments, you may have to go outside of city.

Near Airport (in Islamabad), there can be different areas (societies) in which 5 marla plots can be purchased (considering long term investment). Blue World City is considered as the last society from Rawalpindi and Islamabad. In this area, 5 marla plots are available in the price range of 15 lacs to 18 lacs. In the Overseas block, 7 marla plots are available in the price range of 18 lacs to 20 lacs. After this Capital Smart city comes, in which Overseas East lies, where the prices of 5 marla plots may range from 28 lacs to 32 lacs. In the Faisal Town Phase 2, developed by Chaudhary Abdul Majeed sb, 5 marla plots are available in the price range of 22 lacs to 26 lacs. It has already completed balloting. In the Silver City Housing Society, 5 marla plots are available in the price range of 18 lacs to 25 lacs. Silver City is one of the most recommended areas to purchase plots. In the I-16 sector, 5 marla plots are available in the price range of 25 to 30 lacs.

Otherwise, Airport Green Garden, 5 marla plots are available in the price range of 50 lacs to 70 lacs. In the Top City, 5 marla plots are available in the price range of 70 lacs to 85 lacs. In the Faisal Town Phase 1, 5 marla plots are available in the price range of 80 lacs to 90 lacs.

Source:

Gondal Group of Marketing Islamabad - Top 10 Housing Projects Near Islamabad Airport, Price Comparison, LowCost Plot For Sale in Islamabad - https://www.youtube.com/watch?v=3J_5p4aw1e4


Thursday, October 31, 2024

What to do or check while purchasing a plot?

(Source: Pixabay)

It seems good, if you would purchase a shop in a mall or somewhere, rather than purchasing a plot, as it would start giving you rent immediately. Or a house to give you rent or a land, which is on “theka.”

Nevertheless, one of the buying strategies to purchase plots is to purchase several smaller plots rather than purchasing a large land. In this way, your investment will be diversified and risk would be reduced.

It is also important to consult at least three people, three experts.

Do not rush, take your time. For instance, if you would be in hurry, you may purchase a dipped land or a hill, and these are useless in terms of building houses.

Think and work on location. For instance, people may look for the future developments regarding the location, and may purchase a plot. For instance, in Jinnah avenue, Islamabad, one kanal can be sold at about 100 crores.

Reverse commission can be used in terms of purchasing plots. For instance, you may go to the commission agent, and say that I want to purchase a plot at lower prices, and the lower the price of the plot, the more commission I will give to you.

It is also important to check the maintenance charges of the plot. In some cases, maintenance charges can be more than the price. In this case, you may give some amount of your rent (from houses or shops) in maintenance charges.

It is also important to check whether gas, water, and electricity are available.

Also check that the plot is not land locked, which is related to the point that the land is locked and streets or ways in the surrounding are locking the land to reach inside. If there is road with the plot, its resale value increases.

Do research, before purchasing a plot. In this case, you may go to zameen.com or olx, or offices of property agents. You may also ask neighbours. Eventually, do not go with rumours.

Source:

How To Buy A Plot | 10 Tips to buy Property in Pakistan - Azad Chaiwala - https://www.youtube.com/watch?v=Jdg9u0H47lA


Tuesday, October 29, 2024

A reason behind the decline in prices of plots

(Source: Pixabay.com)

In the real estate market, prices are down for the past several months. In this case, government policies obviously have some effect, the lack of commitment of most of the people involved in new housing projects is also an important factor behind the decline in prices. For instance, developers may say that this is our land; this is the time in which we would complete our work, etc. but they are not fulfilling their commitment. In this case, it seems imperative talk about them. In most of the cases, our marketing companies, for their own profits, don’t talk about them. It would also be important to note that most of the developers talk their money, which they have gotten from clients, in some other projects that result in the decline in the progress of the clients’ work.

Source:

MASS Global Marketing-MGM - Real Estate Fraud Alert | Real Estate Business in Pakistan #Pakistan #RealEstateBusiness - https://www.youtube.com/watch?v=PXlPktPNcjs


Sunday, October 27, 2024

Prices in Block E, Phase 8, Bahria Town, Rawalpindi/Islamabad, Pakistan

 

(Source: https://bahriatown.com/)

Bahria Town, Phase 8, has Block E containing different parts, including E1, E2, and E3. E block has mostly the sizes of plots in the range of 10 marlas, though some plots are also available in the size of 1 kanal. The middle ring road side of this area is not only heighted but also has higher prices, such as in the range of 1.25 crores, while the other side from middle ring road has plots in the size range of 90 lacs. During the last 1.5 to 2 years, prices have gone down about 20 lac rupees. Nevertheless, all E1, E2, and E3 areas are possessionable. In the E1, the prices are in the range of 90 lacs to 1 crore. E1 is also a heighted area. In E1, some plots of 6 marlas are also available, the prices of which are in the range of 75 lacs. E2 and E3 have 5 marla plots. In E3, 5 marla plots are available in the price range of 60 lacs.

Source:

Bahria Town Rawalpindi Phase 8 E Block | Price Latest Updates | Advice Associates - Advice Associates - https://www.youtube.com/watch?v=y7f0xpBmp6c


Day 12: A challenge to learn basics of Structural Equation Modeling (SEM) using lavaan and semPlot packages in R

 

During the next 12 days, I will learn and repeat the basics of structural equation modeling (SEM) using lavaan and semPlot packages in R.

You can search my lavaan posts by typing: #UsmanZafarParacha_lavaan , and semPlot posts by typing: #UsmanZafarParacha_semPlot

=============

During this day, I learned and studied about Confirmatory Factor Analysis (CFA) while implementing a polychoric matrix and use the robust diagonally weighted least squares (RDWLS) method to evaluate the model fit using several fit indices such as RMSEA, CFI, TLI, SRMR, and chi-square/DF. This same thing can also be found in one of the research papers, such as that conducted Almeida et al. (2024).

Initially, I loaded the essential libraries and created supposed data using the following lines of codes:

 

library(lavaan)

library(semPlot)

library(psych)

 

set.seed(123)  # For reproducibility

n <- 200  # Number of participants

 

# Simulate ordinal data (Likert scale: 1 to 5)

item1 <- sample(1:5, n, replace = TRUE)

item2 <- sample(1:5, n, replace = TRUE)

item3 <- sample(1:5, n, replace = TRUE)

item4 <- sample(1:5, n, replace = TRUE)

item5 <- sample(1:5, n, replace = TRUE)

 

# Create a data frame

data <- data.frame(item1, item2, item3, item4, item5)

 

Then, using the psych package, the polychoric correlation matrix was determined:

 

polychoric_matrix <- polychoric(data)$rho

 

The CFA model was specified:

 

cfa_model <- '

  Factor1 =~ item1 + item2 + item3

  Factor2 =~ item4 + item5

'

 

fit <- cfa(cfa_model, sample.cov = polychoric_matrix, sample.nobs = n, estimator = "ML")

 

and the model fit was checked:

 

summary(fit, fit.measures = TRUE, standardized = TRUE)

 

Eventually, the CFA model was visualized:

 

semPaths(fit, what = "std", edge.label.cex = 1.2, layout = "tree", style = "lisrel", rotation = 2)

 

 

Sources:

Almeida, D. M., Santos-de-Araújo, A. D., Júnior, J. M. C. B., Cacere, M., Pontes-Silva, A., Costa, C. P., ... & Bassi-Dibai, D. (2024). The best internal structure of the Diabetes Quality of Life Measure (DQOL) in Brazilian patients. BMC Public Health24(1), 580.

ChatGPT


Saturday, October 26, 2024

Some of the most important sectors in DHA, Islamabad/Rawalpindi, Pakistan

(Source: https://www.dhai-r.com.pk/)

Considering the popular sectors of DHA Islamabad/Rawalpindi, Sector A, Sector B, Sector C, and Sector K, are among the most popular sectors. People living in these areas can have access to basic facilities, including banking, saloons, parks, schools, etc. Sector K is also near Golf Course. Considering the prices of most of the plots in Sectors A, B, and C, prices may range from 2.5 crores to 4.5 crores. Plots near main boulevard could be somewhat higher, such as near 3.25 crores. On the other hand, plots away from main boulevard and plots in low-lying areas can also be obtained at lower prices. On the other hand, plots in Sector K can be in the range from 3.5 crores to 4.5 crores.

Source:

Property Gupshup - 💥MOST WANTED sectors in DHA Islamabad Rawalpindi | Property Gupshup - https://www.youtube.com/watch?v=tFVtnk-XpWM


Day 11: A challenge to learn basics of Structural Equation Modeling (SEM) using lavaan and semPlot packages in R


 During the next 12 days, I will learn and repeat the basics of structural equation modeling (SEM) using lavaan and semPlot packages in R.

You can search my lavaan posts by typing: #UsmanZafarParacha_lavaan , and semPlot posts by typing: #UsmanZafarParacha_semPlot

=============

During this day, I loaded lavaan and semPlot, and defined the SEM model, as follows:

# Load the packages

library(lavaan)

library(semPlot)

 

# Define the SEM model

model <- '

  # Direct effect

  productivity ~ management + job_satisfaction + workplace

 

  # Indirect effect

  job_satisfaction ~ management

'

 

Then, a supposed data was developed, as follows:

# Simulate a dataset with the relevant variables

set.seed(123)  # For reproducibility

 

n <- 200  # Number of observations

 

# Simulate random variables for the model

management <- rnorm(n, mean = 5, sd = 2)  # Management style

job_satisfaction <- 0.5 * management + rnorm(n, mean = 0, sd = 1)  # Job satisfaction

workplace <- rnorm(n, mean = 4, sd = 1.5)  # Workplace environment

productivity <- 0.3 * management + 0.4 * job_satisfaction + 0.5 * workplace + rnorm(n, mean = 0, sd = 1)  # Productivity

 

# Combine into a data frame

data <- data.frame(management, job_satisfaction, workplace, productivity)

 

# Inspect the data

head(data)

 

Then, lavaan was used to fit the SEM model, as follows:

 

# Fit the model

fit <- sem(model, data = data)

 

# Display the summary of the SEM results

summary(fit, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE)

 

Eventually, the model is visualized using the semPlot package, as follows:

# Visualize the SEM model

semPaths(fit, what = "std", layout = "tree", edge.label.cex = 1.2,

         style = "ram", nCharNodes = 0, curvePivot = TRUE)

 

Source:

ChatGPT


Friday, October 25, 2024

Margalla Orchards by DHA in Islamabad, Pakistan

 

(Source: Zameen.com)

Margalla Orchards by DHA was launched in 2015. Presently, its transfer is taking place in the office of Federal Government Employee Housing Society, but soon its transfer will start taking place in the DHA, Phase 5 office, which is the main office of DHA. It is near Park Road. Before August, the prices of 1 kanal plots (files) in this area were in the range of 80 lacs to 1 crores. Now, after being linked to DHA, the prices are in the range of 1.6 crore or near or above this, such as above 2 crores. Investment in any area in this place can be of good value. It is about 8500 kanals’ area. Immediately, in its neighbor is Park Enclave, where market rates are above 5 crores at a distance and 6 crores in the start. Comsats University is located in its front. It has different sectors, including A, B, C, etc. Within 3 years, the prices of plots in these sectors can be doubled.

Source:

Real Ustad - 𝐌𝐚𝐫𝐠𝐚𝐥𝐥𝐚 𝐎𝐫𝐜𝐡𝐚𝐫𝐝𝐬 𝐛𝐲 𝐃𝐇𝐀 𝐈𝐬𝐥𝐚𝐦𝐚𝐛𝐚𝐝 - 𝐄𝐯𝐞𝐫𝐲 𝐅𝐢𝐥𝐞 𝐢𝐬 𝐈𝐦𝐩𝐨𝐫𝐭𝐚𝐧𝐭 - https://www.youtube.com/watch?v=33zkpgH7Jdc


Day 10: A challenge to learn basics of Structural Equation Modeling (SEM) using lavaan and semPlot packages in R


 During the next 12 days, I will learn and repeat the basics of structural equation modeling (SEM) using lavaan and semPlot packages in R.

You can search my lavaan posts by typing: #UsmanZafarParacha_lavaan , and semPlot posts by typing: #UsmanZafarParacha_semPlot

=============

During this day, I loaded the essential libraries, and defined the SEM model using the following lines of codes:

 

# Load libraries

library(lavaan)

library(semPlot)

 

# Define the SEM model

model <- '

  # Direct effect of teacher experience on instructional methods

  InstructionalMethods ~ a * TeacherExperience

 

  # Direct effect of instructional methods on student performance

  StudentPerformance ~ b * InstructionalMethods

 

  # Direct effect of teacher experience on student performance

  StudentPerformance ~ c * TeacherExperience

 

  # Moderation: Classroom environment moderates the effect of instructional methods on student performance

  StudentPerformance ~ d * Interaction

 

  # Define indirect (mediation) effect

  indirect := a * b

 

  # Define total effect (direct + indirect effects)

  total := c + (a * b)

'

 

Then, a supposed data is generated using the following lines of codes:

 

# Generate sample data (if real data is not available)

set.seed(123)

n <- 300

data <- data.frame(

  TeacherExperience = rnorm(n, mean = 10, sd = 5),

  ClassroomEnvironment = rnorm(n, mean = 3, sd = 1),

  InstructionalMethods = rnorm(n, mean = 0, sd = 1),

  StudentPerformance = rnorm(n, mean = 75, sd = 10)

)

 

Then a relationship is created and interaction terms are established, as follows:

 

# Create relationships and interaction term

data$InstructionalMethods <- 0.5 * data$TeacherExperience + rnorm(n)

data$StudentPerformance <- 0.3 * data$TeacherExperience +

                           0.6 * data$InstructionalMethods +

                           0.4 * data$InstructionalMethods * data$ClassroomEnvironment +

                           rnorm(n)

data$Interaction <- data$InstructionalMethods * data$ClassroomEnvironment

 

Then we fit the model and visualized the SEM model using the following lines of codes:

 

# Fit the model

fit <- sem(model, data = data)

summary(fit, standardized = TRUE, fit.measures = TRUE)

 

# Visualize the SEM model

semPaths(fit,

         whatLabels = "std",

         layout = "tree",

         edge.color = "blue",

         sizeMan = 6,

         sizeLat = 8,

         fade = FALSE)

 

Source:

ChatGPT