<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Olá useRs,<br>
<br>
Estudei mais sobre as dummies, e após algumas buscas na internet
consegui uma solução para gerá-las "by hand".<br>
<br>
# Making dummy variables from a case with K > 2 levels<br>
# Transforming grown to factor<br>
prep$grown.f <- factor(prep$grown, labels = c("1", "2", "3"))<br>
tapply(prep$lnexp_5y, prep$grown.f, mean) # Silly checking of the
transformation<br>
ido <- sort(unique(prep$grown.f))<br>
contrasts(ido) # Inspecting the binary combinations considering the
first level as reference<br>
length(ido)<br>
dg <- matrix(NA, nrow = nrow(prep), ncol = (length(ido)-1))
#creating empty dummy dataset<br>
dg<br>
d.dim <- (length(ido)-1)<br>
for (j in 1:d.dim) { <br>
dg[,j] <- as.integer(prep$grown.f == ido[j])<br>
}<br>
dg<br>
prep2 <- cbind(prep, dg)<br>
head(prep2)<br>
prep2$"1" <- as.factor(prep2$"1")<br>
prep2$"2" <- as.factor(prep2$"2")<br>
str(prep2)<br>
names(prep2) <- c("lnexp_5y", "gender", "age",<br>
"smoking", "grown", "yearsliving",<br>
"children", "hourshome", "job", "odor_binom",<br>
"behavioral", "risk_perception",<br>
"eyes_a", "nose_a", "run_nose_a", "nausea_a",<br>
"cough_a", "chest_a", "breath_a", "fatigue_a",<br>
"headache_a", "concentration_a", "dizziness_a",<br>
"grown.f", "grown2", "grown3")<br>
prep3 <- prep2<br>
str(prep3)<br>
<br>
Se alguém tiver uma solução mais elegante, por favor adicione seu
comentário. ;)<br>
<br>
Abs,<br>
Vinícius<br>
<br>
<div class="moz-cite-prefix">On 04/08/2015 02:58 PM, Vinícius Lionel
Mateus wrote:<br>
</div>
<blockquote cite="mid:5525260A.7090605@gmail.com" type="cite">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
Prezados useRs,<br>
<br>
Sou um newbie em análise de dados categóricos, e esta é a primeira
vez que uso o pacote lavaan.<br>
<br>
Ao implementar a análise, recebo o seguinte erro:<br>
<br>
<b>Error in muthen1984(Data = X[[g]], ov.names = ov.names[[g]],
ov.types = ov.types, : </b><b><br>
</b><b> unknown ov.types:factor</b><br>
<br>
Acho que estou com problemas de sintaxe, na hora de especificar
uma variável dummy, <b>grown</b>.<br>
O código antes do erro é:<br>
<br>
#### Making dummy variables from a case with K > 2 levels ###<br>
# Transforming grown to factor<br>
raw.data$grown <- factor(raw.data$grown, labels = c("1", "2",
"3"))<br>
class(raw.data$grown)<br>
str(raw.data) #Inspecting the data set<br>
<br>
#the contrast matrix for categorical variable with three levels<br>
contr.treatment(3)<br>
#assigning the treatment contrasts to grown<br>
contrasts(raw.data$grown) = contr.treatment(3)<br>
str(raw.data) #Inspecting the data set<br>
<br>
### centering and rescaling numeric explanatory variables ###<br>
prep$lnexp_5y <- scale(prep$lnexp_5y)<br>
prep$age<-scale (prep$age)<br>
prep$yearsliving <-scale (prep$yearsliving)<br>
prep$hourshome <-scale (prep$hourshome)<br>
str(prep)<br>
<br>
# Building the model<br>
# The observed variable in black is a dummy.<br>
odor1 <- '<br>
# latent variables (measurement model)<br>
rsi =~ eyes_a + nose_a + run_nose_a +<br>
cough_a + chest_a + breath_a<br>
nsh =~ dizziness_a + concentration_a + <br>
headache_a + fatigue_a + nausea_a<br>
psy =~ risk_perception + behavioral<br>
ap =~ lnexp_5y<br>
<br>
<br>
sde =~ gender + smoking + <b>grown</b> + children + yearsliving <br>
oa =~ odor_binom<br>
<br>
#regressions (dependent ~ independent | y ~ x)<br>
rsi ~ ap + oa<br>
psy ~ ap + oa<br>
nsh ~ ap + oa + psy<br>
oa ~ ap + sde<br>
'<br>
# Fitting the model with WLSMV<br>
<a moz-do-not-send="true" href="http://fit1.ml" target="_blank"
rel="nofollow"
onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Ffit1.ml\46sa\75D\46sntz\0751\46usg\75AFQjCNGZqrCGc6TmzS75URauc5Yo000xfg';return
true;"
onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Ffit1.ml\46sa\75D\46sntz\0751\46usg\75AFQjCNGZqrCGc6TmzS75URauc5Yo000xfg';return
true;">fit1.ml</a> <- sem(odor1, data = prep, ordered =
c("grown"), estimator = "WLSMV")<br>
<br>
<br>
Desde já, muito obrigado.<br>
Vinícius<br>
<pre class="moz-signature" cols="72">--
Best regards,
Vinícius Lionel Mateus, MSc (<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lattes.cnpq.br/6501001637020665">http://lattes.cnpq.br/6501001637020665</a>)
Chemistry PhD Student
Atmospheric Chemistry Laboratory - Dep. Chemistry
PUC-Rio - Pontifical Catholic University of Rio de Janeiro
Rua Marquês de São Vicente, 225, Gávea - Rio de Janeiro, RJ - Brazil CEP: 22451-900
Telefone: (+45) 26 28 28 51
(+55) (21) 3527-1327
(+55) (21) 993 - 588 - 051
Skype: vinicius.lionel
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.qui.puc-rio.br/index.html">http://www.qui.puc-rio.br/index.html</a></pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Best regards,
Vinícius Lionel Mateus, MSc (<a class="moz-txt-link-freetext" href="http://lattes.cnpq.br/6501001637020665">http://lattes.cnpq.br/6501001637020665</a>)
Chemistry PhD Student
Atmospheric Chemistry Laboratory - Dep. Chemistry
PUC-Rio - Pontifical Catholic University of Rio de Janeiro
Rua Marquês de São Vicente, 225, Gávea - Rio de Janeiro, RJ - Brazil CEP: 22451-900
Telefone: (+45) 26 28 28 51
(+55) (21) 3527-1327
(+55) (21) 993 - 588 - 051
Skype: vinicius.lionel
<a class="moz-txt-link-freetext" href="http://www.qui.puc-rio.br/index.html">http://www.qui.puc-rio.br/index.html</a></pre>
</body>
</html>