3

I am trying to evaluate the sem model from a dataset, some of the data are in likert scale i.e from 1-5. and some of the data are COUNTS generated from the computer log for some of the activity.

Whereas while performing the fits the laveen is giving me the error as:

lavaan WARNING: some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate

To mitigate this warning I want to scale some of the variables. But couldn't understand the way for doing that.

Log_And_SurveyResult <- read_excel("C:/Users/Aakash/Desktop/analysis/Log-And-SurveyResult.xlsx")

model <- '
  Reward =~ REW1 + REW2 + REW3 + REW4
  ECA =~  ECA1 + ECA2 + ECA3
  Feedback =~ FED1 + FED2 + FED3 + FED4
  Motivation =~ Reward + ECA + Feedback
  Satisfaction =~ a*MaxTimeSpentInAWeek + a*TotalTimeSpent + a*TotalLearningActivityView 
  
  Motivation ~ Satisfaction'

fit <- sem(model,data = Log_And_SurveyResult)

summary(fit, standardized=T, std.lv = T)

fitMeasures(fit, c("cfi", "rmsea", "srmr"))

I want to scale some of the variables like MaxTimeSpentInAWeek and TotalTimeSpent

Could you please help me figure out how to scale the variables? Thank you very much.

Rasik
  • 1,961
  • 3
  • 35
  • 72

2 Answers2

2

As Elias pointed out, the difference in the magnitude between the variables is huge and it is suggested to scale the variables. The warning gives a hint and inspecting varTable(fit) returns summary information about the variables in a fitted lavaan object.

Rather than running scale() separately on each column, you could use apply() on a subset or on your whole data.frame:

## Scale the variables in the 4th and 7h column
Log_And_SurveyResult[, c(4, 7)] <- apply(Log_And_SurveyResult[, c(4, 7)],  2, scale)

## Scale the whole data.frame
Log_And_SurveyResult <- apply(Log_And_SurveyResult,  2, scale)
bathyscapher
  • 1,615
  • 1
  • 13
  • 18
1

You can just use scale(MaxTimeSpentInAWeek). This will scale your variable to mean = 0 and variance = 1. E.g:

    Log_And_SurveyResult$MaxTimeSpentInAWeek <- 
    scale(Log_And_SurveyResult$MaxTimeSpentInAWeek)
    Log_And_SurveyResult$TotalTimeSpent <- 
    scale(Log_And_SurveyResult$TotalTimeSpent)

Or did I misunderstand your question?

Elias
  • 726
  • 8
  • 20
  • how to use that scaled_MaxTime in the `model`? – Rasik Sep 23 '20 at 07:53
  • Why dont you transforme the data before including them in the model? – Elias Sep 23 '20 at 07:55
  • can you help on how to scale before and use that in the model? – Rasik Sep 23 '20 at 07:56
  • i have loaded the data in `Log_And_SurveyResult` variable – Rasik Sep 23 '20 at 07:58
  • still the same warning...i don't know why I am getting the warning `some observed variances are (at least) a factor 1000 times larger than others; use varTable(fit) to investigate`. isn't this the way of doing that to scale? – Rasik Sep 23 '20 at 08:09
  • Try to scale all the variables. Maybe the problem lies not with the two mentioned variables but with others – Elias Sep 23 '20 at 08:11
  • yeah, the warning has gone now, maybe some other variables were also causing the issues...one other question, I have scale the variables that predict the construct `Satisfaction`, but I haven't scale the variables that loads the `Motivation`. So, if we scale some variables do we need to other variables too? – Rasik Sep 23 '20 at 08:16
  • I can not say for sure. But I would say it is not a problem. Furthermore, you standardize your results anyway. `summary(fit, standardized=T, std.lv = T)`. With the input `standardized=T`. So I would say it is not a problem. But as said I am not 100% sure. But I am glab I could help. – Elias Sep 23 '20 at 08:24
  • with `std.lv = T` it is showing error as `Error in .local(object, ...) : unused argument (std.lv = TRUE)` – Rasik Sep 23 '20 at 08:32
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221926/discussion-between-akshaykriti-and-elias). – Rasik Sep 23 '20 at 08:32