[R] structural equation modeling in sem, error, The model has negative degrees of freedom = -3, and The model is almost surely misspecified...
Hi all, I am attempting to learn my way through the sem package by constructing a simple structural model for some of my data on bird diversity, abundance, and primary productivity. I have constructed a covariance matrix between these variables as per the following: S_matrix = matrix(c( + 0.003083259, 0, 0, + 0.143870284, 89.7648490, 0, + 0.276950919, 81.3484101, 215.3570157 ), ncol = 3, byrow = T) rownames(S_matrix) = colnames(S_matrix) = c(dec_mean_EVI, density, ALL_Jack1) I then construct a model using a symbolic ram specification as follows tmodel - specify.model() dec_mean_EVI - density, gam1, NA density - ALL_Jack1, gam2, NA dec_mean_EVI - ALL_Jack1, gam3, NA dec_mean_EVI - dec_mean_EVI, ps1, NA density - density, ps2, NA ALL_Jack1 - ALL_Jack1, theta1, NA dec_mean_EVI - density, theta2, NA dec_mean_EVI - ALL_Jack1, theta2, NA density - ALL_Jack1, theta3, NA I then try to run the sem analysis using the matrix and model. sem_1 - sem(ram = tmodel, S = S_matrix, N = 88, fixed.x = c(dec_mean_EVI)) summary(sem_1) However, I only get the following error message: Error in sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : The model has negative degrees of freedom = -3 In addition: Warning message: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : The following variables have no variance or error-variance parameter (double-headed arrow): density, ALL_Jack1, dec_mean_EVI, density, density, ALL_Jack1 The model is almost surely misspecified; check also for missing covariances. It must be obvious to those experienced with sem, but I can't yet see where I have gone wrong in constructing my matrix or model, any thoughts would be much appreciated. thanks in advance, Alex __ 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] converting NSCA HDF5 files to ASCII
Hi All, I am struggling with the task of converting some MODIS remotes sensed image data in HDF5 format to ASCII format. I have found oblique references to the HDF format in the help files for the packages hdf5, RnetCDF, and ncdf, but nothing that appears to read in an HDF format file and produce an ASCII grid file. I am hoping to avoid having to move to another platform, and I have about 3,000 files to convert, so a batch processing option is preferable (otherwise I would use some of the freely available software packages like HDF look). Any thoughts would be most appreciated. regards Alex Phd Candidate, Centre for Tropical Biodiversity and Climate Change School of Marine and Tropical Biology James Cook University, Townsville Queensland, Australia, 4811 __ 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] calling external .EXE file in R macOSX
Hi All, I am currently working on an analysis which requires a call to an external FORTRAN routine contained within a file called MCDS.EXE. This file is usually called from within a WINDOWS program called DISTANCE. I have some R script from the developers of the original software which apparently makes a call to this .EXE file which i need to re-engineer slightly, but i am having difficulty interpreting how the script makes this call and passes to the EXE file the relevant input command file and data file for processing. I am also unsure if making such a call will work within the OSX environment for a (windows?) executable file. Below is an example from the script which is supposed to make the call. Any suggestions would be much appreciated. Cheers A cds - function (key, adj, L, w, A=NA, xi, zi, file.base,ext.files=F,bootstrap=F) { #Purpose: Driver function to run the mcds.exe engine from R #Updated by Tiago on 19/12/2004 so that it can take an external data and command input files #Usefull if you want to do a non-standard bootstrap analysis of some data analised in distance #and for wich distance is not capable of producing variance estimates #This way, you can call this function inside a bootstrap procedure, as long as you update the #data file at each resample #Inputs: # key- vector string containing key functions # adj- vector string containing adjustment terms # L - total survey effort # A - survey area # xi - vector of perpendicular distances # zi - vector of cluster sizes # file.base - if specified and engine is cds, then the cds input and # output files are written into the current directory, with the # cds.file.base as a prefix and '.txt' as a suffix. E.g., setting # cds.file.base to 'cds' produces 'cds.cmd.txt', 'cds.data.txt', # 'cds.log.txt','cds.stat.txt','cds.plot.txt' and 'cds.boot.txt' # If not specified, these files are created in a temp location and # are deleted at the end. # ext.files - If true, then the funtion uses the external files 'file.base'+'.cms.'+txt' as command file # and 'file.base'+'.data.'+.txt' as data file. Typicaly these files would be the result of # runing Distance in debug mode, and should be placed in the working directory for R. # By default ext.files is false, so the function looks for the files produced by functions # 'create.data.file' and 'create.command.file' # You need to change the input comand file in order for the mcds engine to produce the files # that the function 'read.stats.file' expects, and that means that inside the command file you should define # file names with prefix = file.base # bootstrap - If true, procedure is being called inside a bootstrap routine, and intermediate files # are deleted at each loop step, except the command file #Outputs: list, containing # Nhat.grp, Nhat.ind, mu, nL, Es, LnL, AIC, status # Note - status is an integer: # 1=OK, 2=warnings, 3=errors, 4=file errors, 5=some other problem (e.g., program crash) run.cds-function(cmd.file.name) { #Purpose: runs the MCDS.exe engine and waits for it to finish # *Note* that mcds.exe needs to be in the working directory, or in the # PATH windows environment # variable for this to work, as it makes no attempt to find the # location of the file #Inputs: # cmd.file.name - name of the command file to run #Returns: # A status integer - 1=OK, 2=warnings, 3=errors, 4=file errors, 5=some other problem (e.g., program crash) __ 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] converting character vector hh:mm to chron or strptime 24 clock time vectors
Hi All, I am attempting to work with some data from loggers. I have read in a .csv exported from MS Access that already has my dates and times (in 24 clock format), (with StringsAsFactors=FALSE). head(tdata) LogData date time 177.16 2008/04/24 02:00 261.78 2008/04/24 04:00 375.44 2008/04/24 06:00 489.43 2008/04/24 08:00 595.83 2008/04/24 10:00 696.88 2008/04/24 24:00 I wish to be able to summarise the data using the character vectors $data and $time (daily, monthly averages, maxima of my $LogData for example) so I am trying to get R to recognise the $date and $time columns as valid dates and times. Using... tdata$date2 = as.Date(as.character(tdata$date)) I can get a new column of valid dates, but neither: tdata$time2= strptime(tdata$time,%k) Error in `$-.data.frame`(`*tmp*`, time2, value = list(sec = c(0, 0, : replacement has 9 rows, data has 10 nor trying: tdata$time2=chron(times=as.character(tdata$time, format= hh:mm)) In addition: Warning messages: 1: In unpaste(times, sep = fmt$sep, fnames = fmt$periods, nfields = 3) : wrong number of fields in entry(ies) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 2: In convert.times(times., fmt) : NAs introduced by coercion 3: In convert.times(times., fmt) : NAs introduced by coercion 4: In convert.times(times., fmt) : NAs introduced by coercion gives me any valid times from my time vector. the Chron documentation doesn't mention 24 clocks, strptime neither, and the Rnews issue 1/4 with an article about time is no help... Any thoughts would be much appreciated. regards Alex Anderson James Cook University Townsville, Australia __ 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.