Re: [R] structural equation models in R
Hi Thanoon, Not sure how we can help when you ask such a vague, broad question. But in any case, I would recommend using the package lavaan in R. Look it up: http://lavaan.ugent.be/ Patrick 2014-04-06 6:26 GMT-06:00 thanoon younis thanoon.youni...@gmail.com: hi i need your help to know how can i analysis structural equation models in R. thanks alot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multilevel Modelling
Have you tried running it using lmer() in lme4 instead, see if that helps? Patrick 2014-03-27 6:21 GMT-06:00 Laura Thomas skagandboneg...@hotmail.com: Hi All, I am using R for the purpose of multilevel modelling for the first time. I am trying to examine individuals interpersonal changes in the dependent variable over time and how this varies between groups. I am using the following code: treat.lme1-lme(DependentVariable~Treatment*I(Time-1), random=~1+I(Time-1)|Treatment, data=MLMworkbook2,na.action=na.omit) but receive the error message: Error in lme.formula(DependentVariable ~ Treatment * I(Time - 1), random = ~1 + : nlminb problem, convergence error code = 1 message = iteration limit reached without convergence (10) Any help with this would be much appreciated. Many thanks, Laura structure(list(Participant = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 39L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 41L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 45L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 47L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 49L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 56L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 57L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 62L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 66L, 67L, 67L, 67L, 67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 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
Re: [R] Problems using lmer {lme4}
Hi Andrea, I'm not exactly sure what you're trying to do, but you've included a random effect for a site coefficient that's not even in your list of fixed effects... you're basically allowing the coefficient for site to vary across routes, but you're never including the coefficient in the first place. Given the appropriate nested structure (I haven't looked at your data), a model that should run would be: m2 - lmer(cbind(punto6,5) ~ sp + site + (site|route) ,family=binomial,data = d) The problem here is I'm not sure this is what you mean to do... If you could way simplify your example (for example, by including a small number of mock observations with only the relevant variables, in a table instead of in R syntax), that would be helpful. Patrick 2013/5/17 Andrea Goijman agoij...@cnia.inta.gov.ar: Dear R list, I'm attaching a sample of my data which consists on the presence/absence (punto6, binomial n=5 occasions) of different species (sp), on different sites (site) within routes ('route). First, I want to be able to find if there is autocorrelation of the response variable between the sites within each route. For this I start testing 2 models, but when I try to run the second model, to test for the random effects of sites within routes R stops working! I'm not being able to find out why r is crashing... and whay am I doing wrong. Thanks! Andrea ### #dput(d) d-structure(list(site = structure(c(55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 55L, 56L, 57L, 58L, 59L, 60L, 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 229L, 230L, 231L, 232L, 233L, 234L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 331L, 332L, 333L, 334L, 335L, 336L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 389L, 390L, 391L, 392L, 393L, 394L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 205L, 206L, 207L, 208L, 209L, 210L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 163L, 164L, 165L, 166L, 167L, 168L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L, 247L, 248L, 249L, 250L, 251L, 252L), .Label = c(102-1, 102-2, 102-3, 102-4, 102-5, 102-6, 1023-1, 1023-2, 1023-3, 1023-4, 1023-5, 1023-6, 1027-1, 1027-2, 1027-3, 1027-4, 1027-5, 1027-6, 1028-1, 1028-2, 1028-3, 1028-4, 1028-5, 1028-6, 1032-1, 1032-2, 1032-3, 1032-4, 1032-5, 1032-6, 1034-1, 1034-2, 1034-3, 1034-4, 1034-5, 1034-6, 1036-1, 1036-2, 1036-3, 1036-4, 1036-5, 1036-6, 1041-1, 1041-2, 1041-3, 1041-4, 1041-5, 1041-6, 1046-1, 1046-2, 1046-3, 1046-4, 1046-5, 1046-6, 105-1, 105-2, 105-3, 105-4, 105-5, 105-6, 107-1, 107-2, 107-3, 107-4, 107-5, 107-6, 108-1, 108-2, 108-3, 108-4, 108-5, 108-6, 1101-1, 1101-2, 1101-3, 1101-4, 1101-5, 1101-6, 1104-1, 1104-2, 1104-3, 1104-4, 1104-5, 1104-6, 1108-1, 1108-2, 1108-3, 1108-4, 1108-5, 1108-6, 111-1, 111-2, 111-3, 111-4, 111-5, 111-6, 1113-1, 1113-2, 1113-3, 1113-4, 1113-5, 1113-6, 1116-1, 1116-2, 1116-3, 1116-4, 1116-5, 1116-6, 1121-1, 1121-2, 1121-3, 1121-4, 1121-5, 1121-6, 1204-1, 1204-2, 1204-3, 1204-4, 1204-5, 1204-6, 1205-1, 1205-2, 1205-3, 1205-4, 1205-5, 1205-6, 1207-1, 1207-2, 1207-3, 1207-4, 1207-5, 1207-6, 1212-1, 1212-2, 1212-3, 1212-4, 1212-5, 1212-6, 202-1, 202-2, 202-3, 202-4, 202-5, 202-6, 205-1, 205-2, 205-3, 205-4, 205-5, 205-6, 207-1, 207-2, 207-3, 207-4, 207-5, 207-6, 208-1, 208-2, 208-3, 208-4, 208-5, 208-6, 211-1, 211-2, 211-3, 211-4, 211-5, 211-6, 213-1, 213-2, 213-3, 213-4, 213-5, 213-6, 214-1, 214-2, 214-3, 214-4, 214-5, 214-6, 217-1, 217-2, 217-3, 217-4, 217-5, 217-6, 218-1, 218-2, 218-3, 218-4, 218-5, 218-6, 219-1, 219-2, 219-3, 219-4, 219-5, 219-6, 223-1, 223-2, 223-3, 223-4, 223-5, 223-6, 302-1, 302-2, 302-3, 302-4, 302-5, 302-6, 305-1, 305-2, 305-3, 305-4, 305-5, 305-6, 308-1, 308-2, 308-3, 308-4, 308-5, 308-6, 311-1, 311-2, 311-3, 311-4, 311-5, 311-6,
Re: [R] How can I extract part of the data with a selection criterion?
Hi, Try ab[a==3,] You're selecting only rows for which a==3 (before the comma), and all columns (empty condition for column index, after the comma) Patrick 2013/5/9 jpm miao miao...@gmail.com: Hi, As an example, how can I get the data such that field a of ab, ab[a], equals 3? I expect the answer to be the union of 2 and 4, as Thanks, a-c(1,3,4,3,5,6,5) b-c(2,4,6,7,3,1,2) ab-data.frame(a,b) ab a b 1 1 2 2 3 4 3 4 6 4 3 7 5 5 3 6 6 1 7 5 2 ab[a==3] Error in `[.data.frame`(ab, a == 3) : undefined columns selected ab[ab[a]==3] [1] 3 3 4 7 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Assigning a variable value based on multiple columns
Hi Jason, I think that the easiest for you would be to keep your current elseif statements as is, but change your NA into something else (e.g., -999, or anything else). To do this in one line, you can use the package gdata. In this code, I assume that your data are stored in the variable dataset: ### #install package gdata if not yet installed install.packages(gdata) #load package gdata library(gdata) #change NA into -999 dataset - NAToUnknown(dataset, -999) #do your ifs/ifelses here... #... #... #change -999 back into NA dataset - unknownToNA(dataset, -999) And that should do it. Hope this helps, Patrick 2013/4/24 Jason Stout, M.D. jason.st...@duke.edu Hi All, I'm hoping someone can help me with a relatively simple problem. Take the following dataset: IDDiabetesESRDHIVContact 100NA0 210NA0 3NA 100 40NA 01 51110 I want to generate a column called TSTcutoff based on the values in the row. TSTcutoff would be the lower of 15 (if Diabetes=ESRD=HIV=Contact=0), 10 (if Diabetes or ESRD=1 AND HIV=Contact=0), or 5 (if HIV OR Contact=1). I was thinking this could be done with a series of IFELSE statements, but the NA values make this more challenging. I want to ignore NA values when calculating TSTcutoff. So the final dataset should look like this: IDDiabetesESRDHIVContact TSTcutoff 100NA015 210NA0 10 3NA 10010 40NA 015 511105 Thanks for any suggestions. Jason Stout, MD, MHS Box 102359-DUMC Durham, NC 27710 FAX 919-681-7494 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Regarding Modeling - Please! QUICK HELP
Hi Andrew, I don't know the dataset at all (and you seem to assume that your readers will), but anyway: it looks like you're trying to do an intercept-only model. If that's the case, try: logmod11 - lmer(log(Reaction) ~ 1 + (1|Subject),REML=FALSE) 1 is the intercept, and anything in parentheses are your random effects--in this case, the intercept is random, and your level-2 class variable is Subject (several lines per Subject). If you want to add Days as a predictor, try: logmod11 - lmer(log(Reaction) ~ 1 + Days + (Days|Subject),REML=FALSE) Here, both the intercept and the coefficient for Days are random (allowed to vary for each Subject). Don't forget to include the dataset after your formula if it's not attached to your environment. Hope this helps, Patrick 2013/4/24 Andrew Cochrane jandrew.cochr...@gmail.com: I'm a student currently working with the *sleepstudy* dataset in matrix.pkg. It deals with the reaction times of sleep deprived students over a period of days. I am trying to model reaction times in order to describe the variation between students by days they havent slept. This is what I'm running in R, but unfortunately I'm missing something: logmod11 - lmer(log(Reaction) ~ (Subject|Days),REML=FALSE) This is obviously incorrect, so If someone could give me some quick help I'd really appreciate it. Thanks! -- J. Andrew Cochrane University of Illinois | 2013 College of Liberal Arts and Sciences | Statistics (630) 991-7502 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] creating dummy variables
Hello Shyam, if your data is stored in variable dataset, for example, the following code will create the desired dummy-coded variables and attach them to the dataset: ## #init vars SWHE=BARL - vector(length=nrow(dataset)) SWHE[]=BARL[] - 0 #initialize dummy-coded vars with all 0s #fill in variables SWHE[grep(SWHE, dataset$crop)] - 1 #grep returns the indices where a match is found, see ?grep BARL[grep(BARL, dataset$crop)] - 1 #attach new dummy codes to dataset dataset$SWHE - SWHE dataset$BARL - BARL ## Hope this helps, Patrick 2013/4/20 shyam basnet shyamabc2...@yahoo.com Hello R-users, The below is a snippet of my data: fid crop year value 5_1_1 SWHE 1995 171 5_1_1 SWHE 1997 696 5_1_1 BARL 1996 114 5_1_1 BARL 1997 344 5_2_2 SWHE 1995 120 5_2_2 SWHE 1996 511 5_2_2 BARL 1996 239 5_2_2 BARL 1997 349 Here, I want to create dummy variables with the names of the content of a column 'crop' in a way that the new variable 'SWHE' would receive a value of 1 if the column 'crop' contains 'SWHE' and 0 otherwise. So, I would have two new variables SWHE and BARL as below: fid crop year value SWHE BARL 5_1_1 SWHE 1995 171 1 0 5_1_1 SWHE 1997 696 1 0 5_1_1 BARL 1996 114 0 1 5_1_1 BARL 1997 344 0 1 5_2_2 SWHE 1995 120 1 0 5_2_2 SWHE 1996 511 1 0 5_2_2 BARL 1996 239 0 1 5_2_2 BARL 1997 349 0 1 Cheers, Shyam Nepal [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.