Metafor measure argument error - r

I have calculated effect size and pooled SE in the way that I wanted. Only thing is drawing a forest plot and let metafor calculate the summary effect size. I have over 30 .csv data files to plot separately. When I do that with the following data (below), it plots and calculates summary effect smoothly.
DeltaPI Spooled
-75.35224985 7.618629848
-51.85221078 7.513461236
-37.77455275 7.164279414
The line I use is:
meta1<-rma(yi=mydata$DeltaPI, sei=mydata$Spooled)
forest(meta1,slab=paste(mydata$Study,mydata$Genotype..Experimental.),showweight=TRUE,alim=c(-100,25),at=c(-100,-50,0,25),xlab="Percentage Change of PI Score",cex=0.7,cex.lab=1,col="red")
However, when I try to do same thing with some other .csv files I have, rma gives an error and asks for 'measure' argument to plot the output. And since the measure is already DeltaPI i calculated manually, I don't want to use.
Weirdly, even if I change the data in those don't working files with the one that working properly(3 data rows above), it still gives the same error. Although, the same data works properly in some other .csv file.
So I'm not clear why I am getting the error and what is the solution.
Any comment would be appreciated!

My guess is that this has nothing to do with the plotting, but occurs when the rma() command is run. And it sounds to me that there are issues with how variables are named in the data that you are reading in. Now you are reading in data from .csv files, but this is probably what is happening:
> library(metafor)
> dat <- data.frame(DeltaP1 = c(.2,.4), Spooled=c(.1,.1))
> rma(dat$DeltaPI, sei=dat$Spooled)
Error in rma(dat$DeltaPi, sei = dat$s) :
Specify the desired outcome measure via the 'measure' argument.
So, in essence, you should carefully check the variable names.

Related

vegan doesn't recognise column names, but it also does recognise them

I'm trying to run RDA analysis using the R package 'vegan'
If I go with the below, using column headers, I get the error "object "width" not recognised". Suggesting that I haven't imported column headers properly.
rda(width+height~age+weight, data=mydata)
But
if I go with the below, it works, so obviously it recognises headers
rda(mydata$width+mydata$height~mydata$age+mydata$weight)
Similarly, other packages recognise headers for example the below works fine.
ggplot(mydata,aes(height, width))
Presumably it's an issue with the use of "data=mydata". I'm baffled and feel it's probably something super simple I'm overlooking, but I have tried and tried to no avail. It was going fine the other day.
As per the help page of rda the left hand side of your formula should be a community data matrix, and data should specify a data frame containing the variables on the right hand side of the formula.
As such, when you pass column names to the left hand side of the formula (e.g. your first line of code), rda is not looking within mydata for those columns and so fails.
In your second line of code you specify where width and height are found, so it is able to run.
You could run it like this:
response <- data.frame(height=mydata$height,width=mydata$width)
rda(response ~ age + weight, data=mydata)
Have a look through the documentation for cca/rda and you'll see example code - try to get your data into the same format as the examples.

How to block bootstrap in R?

I'm trying to run a block bootstrapping function on some time series data (monthly interest rates for ~15 years).
My data is in a csv file with no header, all comprising one column and going down by row.
I installed the package bootstrap because tsboot wouldn't work for me.
Here is my code:
testFile = read.csv("\\Users\\unori/sample_data.csv")
theta <- function(x){mean(x)}
results = bootstrap(testFile,100,theta)
It tells me there are at least 50 errors. All of them say "In mean.default(x) : argument is not numeric or logical: returning NA"
What to do? It runs when I use the example in the documentation. I think it must be how my data is stored/imported?
Thanks in advance.
Try to supply a working, minimal example that reproduces your problem! Check here to see how to make a minimal reproducible example.
The error messages tells you that the thing you want to calculate the mean of, is not a number! So R will just return NA.
Suggestions for debugging:
Does the object 'testFile' exist?
What is the output of
str(testFile)
This works for me:
library(bootstrap)
testFile <- cars[,1]
theta <- function(x){mean(x)}
results = bootstrap(testFile,100,theta)

Error when trying to create log axes in R (xyplot) "Math.factor(x,xbase) : 'log' not meaningful for factors

TL;DR: I'm getting the above (and below) error. How do I fix it?
Since I'm relatively new to R, this has me stumped. I'm trying to create an xyplot where both the axes are log-transformed. I've gotten this far:
library(lattice)
xyplot(`APC-H7-A`~`PE-Cy5-A`,lymphocytes, smooth=FALSE,
xlim=c(-100,10000), ylim=c(-100,10000),
scales=list(x=list(log=10),y=list(log=10)))
And I keep getting an error:
Error in Math.factor(x, xbase) : ‘log’ not meaningful for factors
I'm guessing that the error means something in my code isn't recognised as a number? but I don't really know where to start looking.
Lymphocytes is an object of flowFrame class, within the flowCore package:
Description. This class represents the data contained in a FCS file or similar data structure. There are three parts of the data:*
A numeric matrix of the raw measurement values with rows=events and columns=parameters
Annotation for the parameters (e.g. the measurement channels, stains, dynamic range)
Additional annotation provided through keywords in the FCS file*
This is a complex data structure and it is not straightforward to access the raw data. The manual page of flowFrame (see help(flowFrame)) says that we can index this object, and with the exprs method is the way to the raw data. Also this class has its own plotting methods, I assume you have a good reason why you choose lattice instead. With loading the example data the way below I could run your plotting code:
require(flowCore)
require(lattice)
data(GvHD)
xyplot(exprs(GvHD[[1]][, "FL4-H"]) ~ exprs(GvHD[[1]][, "FL2-H"]),
smooth=FALSE,
xlim=c(-100,10000),
ylim=c(-100,10000),
scales=list(x=list(log=10),
y=list(log=10)),
xlab = "FL2-H",
ylab = "FL4-H")
I don't know what is FL2-H, FL4-H and index 1 in this data array, but I am sure you will find out quickly as you know your data.

Correctly setting up Shannon's Entropy Calculation in R

I was trying to run some entropy() calculations on Force Platform data and i get a warning message:
> library(entropy)
> d2 <- read.csv("c:/users/SLA9DI/Documents/data2.csv")
> entropy(d2$CoPy, method="MM")
[1] 10.98084
> entropy(d2$CoPx, method="MM")
[1] 391.2395
Warning message:
In log(freqs) : NaNs produced
I am sure it is because the entropy() is trying to take the log of a negative number. I also know R can do complex numbers using complex(), however i have not been successful in getting it to work with my data. I did not get this error on my CoPy data, only the CoPx data, since a force platform gets Center of Pressure data in 2 dimensions. Does anyone have any suggestions on getting complex() to work on my data set or is there another function that would work better to try and get a proper entropy calculation? Entropy shouldn't be that much greater in CoPx compared to CoPy. I also tried it with some more data sets from other subjects and the same thing was popping up, CoPx entropy measures were giving me warning messages and CoPy measurements were not. I am attaching a data set link so anyone can try it out for themselves and see if they can figure it out, as the data is a little long to just post into here.
Data
Edit: Correct Answer
As suggested, i tried the table(...) function and received no warning/error message and the entropy output was also in the expected range as well. However, i apparently overlooked a function in the package discretize() and that is what you are supposed to use to correctly setup the data for entropy calculation.
I think there's no point in applying the entropy function on your data. According to ?entropy, it
estimates the Shannon entropy H of the random variable Y from the corresponding observed counts y
(emphasis mine). This means that you need to convert your data (which seems to be continuous) to count data first, for instance by binning it.

CSV file to Histogram in R

I'm a total newbie with R, and I'm trying to create a histogram (with value and frequency as the axises) from a csv file (just one row of values). Any idea how I can do this?
I'm also an R newbie, and I ran into the same thing. I made two separate mistakes, actually, so I'll describe them both here.
Mistake 1: Passing a frequency table to hist(). Originally I was trying to pass a frequency table to hist() instead of passing in the raw data. One way to fix this is to use the rep() ("replicate") function to explode your frequency table back into a raw dataset, as described here:
Creating a histogram using aggregated data
Simple R (histogram) from counted csv file
Instead of that, though, I just decided to read in my original dataset instead of the frequency table.
Mistake 2: Wrong data type. My raw data CSV file contains two columns: hostname and bookings (idea is to count the number of bookings each host generated during some given time period). I read it into a table.
> tbl <- read.csv('bookingsdata.csv')
Then when I tried to generate a histogram off the second column, I did this:
> hist(tbl[2])
This gave me the "'x' must be numeric" error you mention in a comment. (It was trying to read the "bookings" column header in as a data value.)
This fixed it:
> hist(tbl$bookings)
You should really start to read some basic R manual...
CRAN offers a lot of them (look into the Manuals and Contributed sections)
In any case:
setwd("path/to/csv/file")
myvalues <- read.csv("filename.csv")
hist(myvalues, 100) # Example: 100 breaks, but you can specify them at will
See the manual pages for those functions for more help (accessible through ?read.table, ?read.csv and ?hist).
To plot the histogram, the values must be of numeric class i.e the data must be of numeric value. Here the value of x seems to be of some other class.
Run the following command and see:
sapply(myvalues[1,],class)

Resources