Using CAPdiscrim and receiving Error missing value where TRUE/FALSE needed - merge

I have a dataset where I am running CAP on different variables. I want to compare age to each of the variables, so I have merged Age and Reprostat into it's own column. But when I run CAP on this new column, it gives me this error:
Error in if (result1$percent > correct) { : missing value where TRUE/FALSE needed
This is the code for merging the columns and the first line of CAP which gives me the error
smetadat$AgeReprostat<-as.factor(paste(smetadat$Age,smetadat$ReproStat,sep=""))
Ordination.model2<-CAPdiscrim (samples~AgeReprostat, data = smetadat,dist="euclid",
axes=0,m=0,permutations=0,add=T)
I've checked and there aren't any NA values, this also happens when I merge age and region, however not for age and sex.
Any ideas why I can't run CAP on only some of the merged data columns? Thank you!

Related

In Grafana, how do we deal with queries that return 0 rows in a chart/panel?

I’m running into a problem that might be self inflicted but I’m a noob and I’m still stumbling thru this dashboard I inherited.
We are using Grafana 8.1.5. I inherited a dashboard with a panel that is giving this error message:
“failed to convert long to wide series when converting from dataframe: can not convert to wide series, input has null time values” error.
I think I know the cause but I don’t know how to fix it. The data source is from a MySQL database. When we select “All” under the dropdown “Org”, we don’t get this error and we get 8 rows back and are expecting 8 rows.
When we select one org (in this example “Data Protection”) under the dropdown “Org”, we do get the error and we get 5 rows back. I think because 3 queries return 0 rows, we are getting this error.
Each pie slice has its own SQL query to get data. For the queries that return 0 rows, I tried selecting some of the “Standard options” to fix it but it doesn’t seem to work. I tried to play around with the Min, Max, and “No Value” settings and enter values larger than 0 but I still get this error. The initial values for Min and Max were "auto" and "No Value" was blank but the screenshot is when I left them as "1" while I was messing with them.
What do I need to do to make the message go away? Is the message benign and I shouldn’t worry about it since it looks like we’re still printing out the pie chart?
Write SQL, which returns record with zero value instead of empty result. In theory zero value, won't be visible in the pie chart and you will have still record for dataframe transformation, so that one won't be failing.
So I accidentally stumbled across the answer. What happened is the query returned data formatted as "Time Series" instead of "Table". Because some of the data didn't have values for the specified time, the time value was Null.
Since it was Null, the chart returned this error message. The fix was to select "Table" as the format. Then the chart won't care about the time value being Null and the missing data appears as 0 in the legend and we don't get the error message anymore.

how to multiply variable to each element of a column in database

I am trying to add a column to a collection by multiplying the 0.9 to existing database column recycling. but I get a run time error.
I tried to multiply 0.9 direction in the function but it is showing error, so I created the class and multiplied it there yet no use. what could be the problem?
Your error message is telling you what the problem is: your database query is using GROUP BY in an invalid way.
It doesn't make sense to group by one column and then select other columns (you've selected all columns in your case); what values would they contain, since you haven't grouped by them as well (and get one row returned per group)? You either have to group by all the columns you're selecting for, and/or use aggregates such as SUM for the non-grouped columns.
Perhaps you meant to ORDER BY that column (orderBy(dt.recycling.asc()) if ascending order in QueryDSL format), or to select all rows with a particular value of that column (where(dt.recycling.eq(55)) for example)?

How to stop date when someone dies

I have an access database for my dairy farm. I have one field named DateBorn, a module function fAge, and an unbound field named AgeNow. For this I have the expression:
=IIf(IsNull([DateBorn]),"",fAge([DateBorn]),Date()))
With this expression, whenever I type in a value for DateBorn, it calculates age for me in years, months, and days. It has worked fine thus far.
Now I want to add something to it; another field named DateDied. I want an expression that whenever I put DateDied, it should stop calculating age for that particular record.
I'm not sure if you made a mistake in your sample regarding calling the function fAge().
I expect it needs two date parameters.
That expression always calculates the age, but for people who died it uses DateDied instead of Date():
=IIf(IsNull([DateBorn]),"",fAge([DateBorn],NZ([DateDied],Date())))
If in case of dead people there shouldn't be any calculated age use this:
=IIf(IsNull([DateBorn]) Or Not IsNull([DateDied]),"",fAge([DateBorn],Date()))

How to fit a kernel density estimate on a pyspark dataframe column and use it for creating a new column with the estimates

My use is the following. Consider I have a pyspark dataframe which has the following format:
df.columns:
1. hh: Contains the hour of the day (type int)
2. userId : some unique identifier.
What I want to do is I want to figure out list of userIds which have anomalous hits onto the page. So I first do a groupby as so:
df=df.groupby("hh","userId).count().alias("LoginCounts)
Now the format of the dataframe would be:
1. hh
2. userId
3.LoginCounts: Number of times a specific user logs in at a particular hour.
I want to use the pyspark kde function as follows:
from pyspark.mllib.stat import KernelDensity
kd=KernelDensity()
kd.setSample(df.select("LoginCounts").rdd)
kd.estimate([13.0,14.0]).
I get the error:
Py4JJavaError: An error occurred while calling o647.estimateKernelDensity.
: org.apache.spark.SparkException: Job aborted due to stage failure
Now my end goal is to fit a kde on say a day's hour based data and then use the next day's data to get the probability estimates for each login count.
Eg: I would like to achieve something of this nature:
df.withColumn("kdeProbs",kde.estimate(col("LoginCounts)))
So the column kdeProbs will contain P(LoginCount=x | estimated kde).
I have tried searching for an example of the same but am always redirected to the standard kde example on the spark.apache.org page, which does not solve my case.
It's not enough to just select one column and convert it to an RDD; you need to also select the actual data in that column for it to work. Try this:
from pyspark.mllib.stat import KernelDensity
dat_rdd = df.select("LoginCounts").rdd
# actually select data from RDD
dat_rdd_data = dat_rdd.map(lambda x: x[0])
kd = KernelDensity()
kd.setSample(dat_rdd_data)
kd.estimate([13.0,14.0])

The value expression for the texttrun 'Textbox86.Paragraphs[0].TextRuns[0]' contains an error: [BC30451] Name 'IFF' is not declared

I am newbie and designing SSRS. Used Row Groups(DistrictName,StoreName,Employee_Name) and Column Groups (MetricsOrder,MetricsName,Year,Month).
Finally it prints 2 total value.
First it prints District Total and another one is the overall total. I need to Check some condition and the value may differ upon the condition.
Here is my expression. Checking weather is it current month. If so, multiply SUM values with RR(Parameter). If not, just print the SUM value
IFF((MONTH(TODAY())=Fields!Month.Value),Sum(Fields!MetricValue.Value)*Parameters!RR.Value,Sum(Fields!MetricValue.Value)
When i run the Report im getting the below error.
An error occured during local report processing. The definition of the
report '/Report11TRIAL2 is invalid'. The value expression for the
texttrun 'Textbox86.Paragraphs[0].TextRuns[0]' contains an error:
[BC30451] Name 'IFF' is not declared.
Could any one help me to fix this error.
I believe the expression should be:
IIF((MONTH(TODAY())=Fields!Month.Value),Sum(Fields!MetricValue.Value)*Parameters!RR.Value,Sum(Fields!MetricValue.Value)
IIF, not IFF.