Sunday, October 20, 2024

Day 5: 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 packages. Then, defined the model using the following lines of codes:

 

 

# Define the SEM model

model <- '

  # Direct effects

  achievement ~ teaching_quality + peer_support + engagement

 

  # Indirect effects

  engagement ~ peer_support

 

  # Covariances (optional if you want to assess relationships between predictors)

  peer_support ~~ teaching_quality

'

 

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

 

# Simulate data (for the sake of demonstration)

set.seed(123)

n <- 200

peer_support <- rnorm(n, mean = 5, sd = 2)

teaching_quality <- rnorm(n, mean = 6, sd = 1.5)

engagement <- 0.5 * peer_support + rnorm(n, mean = 3, sd = 1)

achievement <- 0.6 * teaching_quality + 0.3 * peer_support + 0.4 * engagement + rnorm(n)

 

data <- data.frame(peer_support, teaching_quality, engagement, achievement)

 

Then, I fit the SEM model to the data:

 

# Fit the model

fit <- sem(model, data = data)

# Get a summary of the model

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

 

Then, the SEM model is visualized using the following lines of codes:

# Plot the SEM model

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

         nCharNodes = 0, color = list(lat = "blue", man = "green"),

         sizeMan = 6, sizeLat = 8)

Source:
ChatGPT


Day 26: Blender tutorial for making illustrations – Creating Complete Educational Videos


Objective: Combine all elements (diagrams, animations, voiceovers) and export a complete educational video.


1. Preparation: Gather All Materials

  • Diagrams: Gather the diagrams and animations you’ve created in Blender during the previous days (flowcharts, mind maps, brainstorm diagrams).
  • Voiceover Script: Prepare your script that corresponds to the visual content. You should match the timing of the voice with each diagram or animation.
  • Background Audio (Optional): Choose soft background music or ambient sounds if you plan to include them.

2. Set Up the Blender Workspace

  • Open Blender and organize all of your layers.
  • Arrange your different elements (e.g., flowcharts, brainstorm diagrams) in the timeline to create a smooth flow between them.
  • If you haven't already, create transitions between different scenes (for example, fade-in or fade-out between diagrams).

3. Refining Animations

  • Go through each of the animated diagrams to ensure smooth transitions and movements.
  • Refine the timing: Make sure that every animation (text appearing, diagram growing, camera movements) is timed correctly.
    • Key Considerations:
      • No abrupt cuts between scenes unless intentional.
      • Adjust the speed of transitions based on your narration speed.

4. Add Voiceover to Blender

  • Audio Setup: Go to the "Video Sequencer" within Blender.
  • Import Audio: Drag and drop your pre-recorded voiceover file (e.g., .mp3 or .wav) into the timeline.
  • Sync Audio and Visuals: Play back the animation with your voiceover, adjusting the timing of visuals to match the narration.
    • Pro Tip: Make sure key visual elements (like text labels or flowcharts) appear right as you speak about them.

5. Polish with Background Audio (Optional)

  • If using background music, import it into the same timeline and adjust the volume to ensure it doesn’t overpower your voice.
  • Fade in/out the music where necessary (e.g., intro, outro).

6. Adding Subtitles (Optional)

  • To improve accessibility, you can add subtitles within Blender using the Text Editor or add them in post-production software like DaVinci Resolve, if desired.

7. Final Video Export

  • Settings:
    • Render size: 1920 x 1080 (Full HD)
    • Frame rate: 24-30 fps (based on your target platform)
    • Format: MP4 with H.264 codec for compatibility and good compression.
  • Go to the Render Properties in Blender.
  • Under the Output Tab, set the correct file format and directory for export.
  • Click Render Animation to create your final video.

8. Preview the Final Video

  • Watch the entire video to ensure that all elements (diagrams, animations, voiceovers) are working seamlessly.
  • Check for any timing issues between the voice and visuals.

9. Export and Save

  • Save the project file for future edits.
  • Export the final video again if any last-minute changes were made.

Outcome:

A complete educational video with flowcharts, animations, and voice narration, ready to be shared on your YouTube channel.

Source:
ChatGPT


Saturday, October 19, 2024

Day 4: 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, essential libraries, including lavaan and semPlot are loaded. Then, an SEM model is specified showing how diet and exercise affect cardiovascular disease both directly and indirectly through mental health. Following lines of codes can be used:

 

library(lavaan)

library(semPlot)

 

# Model specification

model <- '

  # Direct effects

  mental_health ~ diet + exercise

  cardiovascular_disease ~ diet + exercise + mental_health

 

  # Indirect effects (via mental health)

  cardiovascular_disease ~ mental_health

'

 

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

 

set.seed(123)

n <- 200  # number of participants

 

# Simulate data

diet <- rnorm(n, mean = 50, sd = 10)

exercise <- rnorm(n, mean = 30, sd = 8)

mental_health <- 0.4 * diet + 0.6 * exercise + rnorm(n)

cardiovascular_disease <- 0.5 * diet + 0.3 * exercise + 0.7 * mental_health + rnorm(n)

 

# Combine into a data frame

data <- data.frame(diet, exercise, mental_health, cardiovascular_disease)

 

Then the lavaan function is used to fit the specified model to the data, using the following lines of codes:

 

fit <- sem(model, data = data)

 

# View the summary of the results

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

 

Then, the SEM can be visualized using the semPlot using the following lines of codes:

 

# Create a SEM plot

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

         sizeMan = 7, sizeLat = 10, asize = 2, color = "lightblue")

Source:
ChatGPT

 


Post 30/30: VFX tutorial for Blender – Final Project & Showreel Creation – Blender VFX Tutorial


Goal: Showcase all your learned VFX skills in a short, polished animation that demonstrates your growth over the last 30 days. This project will serve as a portfolio piece and a foundation for future projects.

Step-by-Step Guide:

1.     Planning the Scene

    • Decide on the theme of your final project. It could be a combination of particles, physics, camera movements, and lighting effects.
    • Sketch out a storyboard or rough idea of what will happen in your 10-15 second animation. Keep it simple but visually impactful (e.g., a meteor crashing, a magical particle explosion, or a cloth falling over an object).

2.     Setting Up the Scene

    • Objects: Start by adding the main elements (such as the meteor, landscape, or objects interacting with particles). Use your knowledge of object manipulation, modeling, and modifiers.
    • Lighting: Use dynamic lighting to highlight the important parts of the scene. Remember the lighting techniques you've learned (like animating lights for a dramatic effect).

3.     Animating the Scene

    • Keyframes: Animate the main elements using keyframes. This could include objects falling, explosions, or camera movements.
    • Physics: Add physics simulations such as rigid bodies, cloth, or fluid (depending on your project).
    • Particles: Incorporate particles or smoke simulations to enhance the visual effects. For example, add particle trails or an explosion effect at a key moment.

4.     Advanced Camera Effects

    • Camera Animation: Animate the camera to create a cinematic feel, such as zooming in on the action or panning across the scene.
    • Depth of Field and Motion Blur: Add depth of field and motion blur to give your animation a professional look.

5.     Compositing

    • If your scene has multiple layers (e.g., smoke, particles, and characters), use Blender’s compositor to combine them. Add effects like glow, color correction, or vignette to enhance the final look.

6.     Rendering

    • Render Settings: Set up your final render. Make sure to use optimal settings for animation (e.g., appropriate resolution, frame rate, and sampling).
    • Test Render: Do a test render of a few frames to ensure everything looks as expected.
    • Full Render: Once satisfied, render your full 10-15 second animation. Depending on complexity, this could take some time.

7.     Create the Showreel

    • Combine all your best work from the past 30 days into a short showreel (optional but recommended). You can include clips from Day 1 to Day 29 and finish with your final project.

8.     Post-Production (Optional)

    • Use video editing software (like Blender’s video editor or external software) to add sound effects, music, or additional editing to polish the final animation.

9.     Final Shareable Visual

    • Export your animation in a shareable format (such as .mp4 or .mov).
    • Share your final project online to showcase your progress!

This guide wraps up your 30-day Blender VFX journey with a comprehensive project that ties together all the skills you've learned, from particles and physics to lighting and animation.

Source:
ChatGPT

Day 25: Blender tutorial for making illustrations – Editing and Refining Your Illustrations

Objective: Learn how to refine your illustrations to make them look more polished and professional by focusing on details like layout, color harmony, smoother animations, and overall presentation.


Step 1: Review the Illustration from Previous Days

  • Open Blender and load one of the illustrations you've created (e.g., a mind map, flowchart, or diagram).
  • Review the animation and structure to identify areas for improvement. Consider:
    • Are the text labels clear and easy to read?
    • Do the colors create visual harmony, or do they clash?
    • Is the animation smooth, or does it feel too fast or slow?

Step 2: Refining the Layout

  • Adjust Spacing: Ensure there’s enough space between elements (shapes, text, lines) for clarity. Use Blender’s grid and snapping tools to align objects better.
  • Reorganize Layers: If you have multiple layers (e.g., text, shapes, background), group and name them properly. Make sure elements that belong together are on the same layer.

Tip: Use Shift + A to add guiding elements like empty objects or grids to help align your components.

Step 3: Improving Color Scheme

  • Harmonizing Colors: Consider using a limited color palette to create consistency. Use colors that are easy on the eyes and help viewers focus on important areas.
    • In the Materials tab, experiment with gradients, subtle shading, or pastel tones for a professional look.
    • Use Blender's Color Ramp to create gradients for smooth transitions.

Example: For a medical diagram, you could use soft blues for labels, light grays for background, and a contrasting color (like green or red) for key areas like organs or cells.

Step 4: Smoothing Animations

  • Tweak Keyframes: Go to the timeline and adjust the keyframes of your animations. Focus on:
    • Slowing down transitions if they feel rushed.
    • Adding more fluidity by modifying easing functions (Linear, Ease In/Out). You can find this in the Graph Editor.
    • Fine-tuning camera movement for smooth panning or zooming (use Bezier curves for smoother transitions).

Tip: Use F-curve modifiers in the Graph Editor to automate repetitive movements (like bouncing or rotating).

Step 5: Enhancing Text Readability

  • Modify Font and Size: Go to the Text properties tab and try different fonts or increase the size of key text labels to improve readability.
  • Add Outlines/Drop Shadows: Create better text visibility by adding outlines or subtle drop shadows around your text (under Text Effects in the Shader Editor).

Tip: Stick to sans-serif fonts like Arial or Helvetica for educational content to keep it simple and clear.

Step 6: Adding Final Details

  • Background: Consider replacing a plain background with a simple gradient or a soft abstract shape.
  • Visual Effects: Add subtle glow or shadow effects using the Compositor to make your illustrations pop. This is particularly effective for highlighting key components.

Step 7: Final Quality Check

  • Play the Animation: Run your animation from start to finish to check for smoothness and clarity.
  • Make Adjustments: Fine-tune any last-minute details like timing, positions, or lighting.

Step 8: Save and Backup

  • Save Your Project: Before moving forward, save your refined version as a new Blender file (e.g., Illustration_Final.blend).
  • Render a Preview: Render a low-quality preview to see how the final version would look.

Outcome:

  • A refined version of your illustration with improved layout, color scheme, smooth animations, and professional finishing touches.
  • A clear understanding of how to fine-tune and perfect your visual content for better presentation.

Source:

ChatGPT


Friday, October 18, 2024

Some of the reasons behind the growth of DHA phases in Rawalpindi/Islamabad

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

During the years from 2022 to 2024, almost all sectors (in real estate) in Pakistan faced loss, except some projects that are successful even now. For instance, DHA Rawalpindi/Islamabad, has experienced a good level of profit during the past two years, as compared to all other projects. For instance, considering DHA Phase 2, the property that was about 3 crores to 3.15 crores during the end of 2022 or the start of 2023, now (in 2024) that is about 5 crores to 5.5 crores, and considering DHA Phase 5, the property that was about 1.5 crores to 1.75 crores at that time, now that is about 3 crores to 3.25 crores. This is about 80% to 100% return on investment (ROI).

There can be different reasons for the success of DHA project. One of the first reasons relate to property location, and another reason is that of who’s taking your money, i.e., who is the project developer. Behind DHA phases, project developers are related to Army Welfare Trust (AWT), which is very strong project developer. The AWT is headed by lieutenant general. This is one of the reasons that the people who purchased property in DHA get one of the most secured properties. It is also important to note that even though the economic situation is not good, people have not stopped making homes in DHA.

Another reason is that DHA phases in Rawalpindi/Islamabad have gotten two interchanges through Islamabad Expressway during the past two years. People have found it easy to enter DHA through Islamabad Expressway.

Source:

Makaan Solutions - Real Estate Success: Why DHA Rawalpindi & Islamabad Stand Out (2022-2024) | Makaan Solutions - https://www.youtube.com/watch?v=oqFAFa7SnM8


Day 3: 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, initially lavaan and semPlot packages are loaded and a SEM model is defined using the following lines of codes:

 

# Load the packages

library(lavaan)

library(semPlot)

 

# Define the SEM model

model <- '

  # Direct effect of Perceived Product Quality on Brand Loyalty

  BL ~ c1*PPQ

 

  # Indirect effect via Customer Satisfaction

  CS ~ a*PPQ

  BL ~ b*CS

 

  # Mediation effect (indirect path)

  indirect := a * b

 

  # Total effect

  total := c1 + (a * b)

'

 

In the above code, a path model is defined representing the direct and indirect effects. Direct path is shown by the effect of Perceived Product Quality (PPQ) on Brand Loyalty (BL) and indirect path is shown by the effect of Perceived Product Quality (PPQ) on Customer Satisfaction (CS) on Brand Loyalty (BL).

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

 

# Simulate some data for 300 participants

set.seed(123)

data <- data.frame(

  PPQ = rnorm(300, mean = 5, sd = 1.5),  # Perceived Product Quality

  CS = rnorm(300, mean = 5, sd = 1.5),   # Customer Satisfaction

  BL = rnorm(300, mean = 5, sd = 1.5)    # Brand Loyalty

)

 

# Adding some correlation between variables to make the SEM model meaningful

data$CS <- 0.5 * data$PPQ + rnorm(300, 0, 0.5)   # Satisfaction depends on Product Quality

data$BL <- 0.3 * data$PPQ + 0.4 * data$CS + rnorm(300, 0, 0.5)  # Loyalty depends on both PPQ and CS

 

Then the SEM model is fit to the data using lavaan package using the following lines of codes:

 

# Fit the model to the simulated data

fit <- sem(model, data = data)

 

# Get the summary of the model fit

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

 

Then the model is visualized using the semPlot

 

# Plot the SEM model

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

         edge.color = "black", nCharNodes = 5, style = "ram",

         residuals = FALSE, exoCov = FALSE)

 

Source:
ChatGPT