Displaying isolated points using pm3d Gnuplot - plot

I am plotting 3D histograms using pm3d in Gnuplot. Data is provided below. The sequence of steps in Gnuplot are:
set view map
splot 'test.dat' u 1:2:(log($3)) with pm3d t " ", 'test.dat' u 1:2:(log($3)) t " "
as you can see in this figure:
some data points are not plotted with pm3d, I think because the lack of coordination with neighboring points. I wonder if there is a way to explicitly plot these non-well coordinated points in Gnuplot using pm3d.
Note: The "plot with images" doesn't work in my case, because the data set I have is much more larger than this simple example and the plot looks like fragmented squares.
Thanks.
Data:
1 1 1
1 2 0
1 3 0
1 4 0
1 5 0
1 6 0
1 7 0
1 8 0
2 1 0
2 2 0
2 3 1
2 4 2
2 5 3
2 6 0
2 7 0
2 8 0
3 1 0
3 2 0
3 3 2
3 4 10
3 5 15
3 6 2
3 7 0
3 8 0
4 1 0
4 2 0
4 3 0
4 4 5
4 5 2
4 6 1
4 7 0
4 8 0
5 1 0
5 2 0
5 3 0
5 4 3
5 5 2
5 6 0
5 7 0
5 8 0
6 1 0
6 2 0
6 3 0
6 4 2
6 5 0
6 6 0
6 7 1
6 8 0
7 1 0
7 2 0
7 3 0
7 4 0
7 5 0
7 6 0
7 7 0
7 8 0
8 1 0
8 2 0
8 3 0
8 4 0
8 5 0
8 6 0
8 7 1.1
8 8 0

Related

How to create an empty column

I have to consider three columns of a dataset.
One of them has values from 1 to 10, while the others have values from 2 to 10. I wanted to sum the frequencies for each value for all the three columns but an error appears, I think because two columns don't have values for 1.
How can I solve it?
This is what I have:
take.care
face_prod 2 3 4 5 6 7 8 9 10
anti-age 0 1 0 5 3 8 4 1 3
Hydrating 2 3 1 8 9 14 9 3 9
normal skin 0 0 0 0 4 0 1 0 1
Other 0 1 0 1 1 0 0 0 0
purifying 0 0 1 1 4 7 8 4 5
sensitive skin 0 0 0 0 1 2 0 0 1
look.fundam
face_prod 2 3 4 5 6 7 8 9 10
anti-age 0 0 0 2 2 4 3 5 9
Hydrating 1 0 1 4 12 7 10 5 18
normal skin 0 0 0 0 1 2 1 1 1
Other 0 1 0 0 2 0 0 0 0
purifying 0 1 0 0 3 5 9 3 9
sensitive skin 0 1 0 0 0 0 1 1 1
good.app
face_prod 1 2 3 4 5 6 7 8 9 10
anti-age 0 1 1 3 5 2 3 6 1 3
Hydrating 4 1 5 5 8 9 10 7 4 5
normal skin 0 0 0 0 2 2 1 0 0 1
Other 2 0 1 0 0 0 0 0 0 0
purifying 2 0 1 2 3 4 7 5 5 1
sensitive skin 1 0 0 0 2 0 0 0 0 1
It's not a dataset but the result of the table() function
If there are some levels missing, an option is to standardize with factor and levels specified as 1 to 10
nm1 <- c('take.care', 'look.fundam', 'good.app')
df1[nm1] <- lapply(df1[nm1], factor, levels = 1:10)
and now use the table

data cleaning for plotting data frames

I am currently working with survey data in R studio. I originally had two csv files but I merged them into one. Both CSV files contained sample IDs. The first file also contains bivariate info, while the second contains rating as a continuous variable.
Here is a sample of the data
ID O1 O2 O3 O4 O5 O6 O7 O8 S1 S2 S3 S4 S5 S6 S7 S8
22 0 1 0 1 0 1 0 1 4 6 2 6 4 3 6 2
23 0 1 0 0 1 1 0 1 5 6 10 4 5 7 7 6
24 0 1 1 0 1 0 0 1 7 4 7 8 7 6 3 9
25 0 0 1 1 0 0 1 1 3 5 5 7 4 6.9 6 5
26 0 1 0 0 1 1 0 1 2 2.5 7 5 4 5 4 3
27 0 1 1 1 0 1 0 0 6 3 4 6 5 6 5 6
28 0 1 1 1 0 0 0 1 7 4 2 8 2 1 4 5
29 0 0 1 0 1 1 1 0 2 5 1 2 4 3 2 2
30 0 1 0 1 1 1 0 0 8 2 6 7 1 7 5 4
31 0 0 0 1 0 1 1 1 7 4 3 2 4 5 7 2
32 0 0 1 0 0 1 1 1 4 7 5 3 1 6 2 3
33 0 1 1 0 1 1 0 0 7 4 5 8 8 5 6 7
For example the 0 in O1 corresponds to the 4 in S1.
I want to make a loop that will sum all of the values corresponding to variable 0 and 1.
if value in O1 is 0, add value in S1 to "sum of 0"
if value in O1 is 1, add value in S1 to "sum of 1"
repeat for all columns to get a total value for 0 and 1.
Any strategies or tips would be helpful going forward!

R keras package Error: Python module tensorflow.contrib.keras.python.keras was not found

I have keras installed with devtools from GitHub in R and TensorFlow installed in Python.
However when I run an example Keras command like:
model <- keras_model_sequential()
I get the following:
Error: Python module tensorflow.contrib.keras.python.keras was not
found.
Detected Python configuration:
python: C:\Python35\python.exe
libpython: C:/Python35/python35.dll
pythonhome: C:\Python35
version: 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: C:\Python35\lib\site-packages\numpy
numpy_version: 1.13.0
tensorflow: C:\Python35\lib\site-packages\tensorflow
python versions found:
C:\Python35\python.exe
C:\Python27\\python.exe
C:\Python35\\python.exe
C:\Python36\\python.exe
I had a similar problem. Restart rstudio, load keras and tensorflow libraries, and type use_condaenv("r-tensorflow"). That fixed it for me.
First, you can install the R tensorflow package from here.
Then, you can just install the latest tensorflow version, using install_tensorflow function, as shown in this answer.
After that, just install and update R-keras library. It should use the last version of TensorFlow now, and this could potentially solve your problem. Also, make sure you install the tensorflow version that matches your Python version.
I faced a similar problem and below steps helped to overcome the issue.
Install TensorFlow and Keras from rstudio github.
devtools::install_github("rstudio/tensorflow")
devtools::install_github("rstudio/keras")
Execute the below
tensorflow::install_tensorflow()
tensorflow::tf_config()
I had a similar problem with a conda installation on a Mac (so using install_keras(method = 'conda', conda = '/opt/anaconda3/bin/conda'), which created a virtual environment called r-reticulate under ~/.conda/envs. Then when I tried to instantiate a model just like you do, I was getting an error 'Error: Python module tensorflow.python.keras was not found.'
For me what resolved it is after loading library(keras) execute use_condaenv("r-reticulate", required = TRUE) and then everything worked.
I faced a similar problem.
The issue was solved by updating the tensorflow module from 1.0.1 to 1.2.1
In Windows, I tried all above given solution but didn't work.
It worked for me when I created env using, both in spyder and R
conda create -n keras-tf tensorflow keras
In windows
library(keras)
library(tensorflow)
use_condaenv("keras-tf", required = T)
In Python
import tensorflow as tf
Some times your env and system don't have any problems, it is just the way how you configure Tensorflow and Keras that cause these errors to be raised.
below is how I fixed mine:
{install.packages("tensorflow")
install.packages("keras")
tensorflow::tf_config()
mytf <- tf$compat$v1}
the configuration results shows the following output:
2021-12-09 11:43:39.007746: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-12-09 11:43:39.007931: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
TensorFlow v2.6.2 ()
Python v3.7 (C:/Users/myName/AppData/Local/r-miniconda/envs/r-reticulate/python.exe)
then type:
install_keras()
after that you can test:
mnist <- keras::dataset_mnist() ; mnist
this will give you an output like:
$train
$train$x
, , 1
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16]
[1,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[2,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[3,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[4,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[5,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[6,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[7,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[8,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
....
$train$y
[1] 5 0 4 1 9 2 1 3 1 4 3 5 3 6 1 7 2 8 6 9 4 0 9 1 1 2 4 3 2 7 3 8 6 9 0 5 6 0 7 6 1 8 7 9 3
[46] 9 8 5 9 3 3 0 7 4 9 8 0 9 4 1 4 4 6 0 4 5 6 1 0 0 1 7 1 6 3 0 2 1 1 7 9 0 2 6 7 8 3 9 0 4
[91] 6 7 4 6 8 0 7 8 3 1 5 7 1 7 1 1 6 3 0 2 9 3 1 1 0 4 9 2 0 0 2 0 2 7 1 8 6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 7 1 2 5 9 5 6 7 5 9 8 8 3
[631] 6 9 7 0 7 5 7 1 1 0 7 9 2 3 7 3 2 4 1 6 2 7 5 5 7 4 0 2 6 3 6 4 0 4 2 6 0 0 0 0 3 1 6 2 2
[676] 3 1 4 1 5 4 6 4 7 2 8 7 9 2 0 5 1 4 2 8 3 2 4 1 5 4 6 0 7 9 8 4 9 8 0 1 1 0 2 2 3 2 4 4 5
[721] 8 6 5 7 7 8 8 9 7 4 7 3 2 0 8 6 8 6 1 6 8 9 4 0 9 0 4 1 5 4 7 5 3 7 4 9 8 5 8 6 3 8 6 9 9
....
[ reached getOption("max.print") -- omitted 9000 entries ]

How to generate Classification Analysis tables in R?

So far I have done the discriminant analysis. I generated the posterior probabilities, structure loadings, and group centroids.
I have 1 grouping variable : history
I have 3 discriminant variables : mhpg, exercise, and control
here is the code so far
td <- read.delim("H:/Desktop/TAB DATA.txt")
td$history<-factor(td$history)
fit<-lda(history~mhpg+exercise+control, data=td)
git<-predict(fit)
xx<-subset(td, select=c(mhpg, control, exercise))
cor(xx,git$x)
aggregate(git$x~history,data=td,FUN=mean)
tst<-lm(cbind(mhpg,control,exercise)~history,data=td)
Basically, the above code is for discriminant analysis.
Now I want generate frequency classification and percent classification tables for classification analysis.
my attempted code (which i sampled from someone else to no avail) is:
td[6] <- git$class
td$V6<-factor(td$V6)
ftab<-table(td$history,dt$V6)
prop.table(ftab,1)
Where column 6 is my grouping variable history.
I get the following error when trying to make td$V6 a categorical variable with factor
Error in `$<-.data.frame`(`*tmp*`, "V6", value = integer(0)) :
replacement has 0 rows, data has 50
Can anyone steer me in the right direction? I really don't know why the sample code used a capital V out of nowhere. Below is the data. Column 6 is the grouping variable, history. Column 5 is the discriminant variable, control. column 7 is the discriminant variable, exercise. Column 8 is the discriminant variable, mhpg.
1 3 6 0 2 0 4 2 4 3 0 6 0
1 4 5 0 0 1 2 5 4 6 1 4 1
1 4 4 0 2 1 1 8 6 7 1 2 1
2 4 9 0 2 1 0 6 7 8 1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 0 1 1 1 7 8 9 1 5 0
1 2 7 0 1 1 0 7 5 6 1 5 1
1 3 5 0 1 1 2 7 8 8 1 5 0
2 3 3 1 2 1 2 6 7 6 1 6 0
2 3 6 1 1 1 2 7 6 4 0 7 0
2 4 6 1 3 1 3 6 5 5 0 6 0
2 5 4 1 3 1 3 4 4 3 0 6 0
Try:
tbl <- table(td$history,git$class)
tbl
# 0 1
# 0 13 2
# 1 1 34
prop.table(tbl)
# 0 1
# 0 0.26 0.04
# 1 0.02 0.68
These are the classification tables.
Regarding why your "borrowed" code does not run, there are too many possibilities.
First, if you import the data set you provided without column names, R will assign names Vn where n is 1,2,3, etc. But if this was the case none of your code would run as you refer to columns history, control, etc. So at least those must be named properly.
Second, in the line:
ftab<-table(td$history,dt$V6)
you refer to dt$V6. AFAICT there is no dt (is this a typo?).

Cut value in creating table

I have following type of data:
mydata <- data.frame (yvar = rnorm(200, 15, 5), xv1 = rep(1:5, each = 40),
xv2 = rep(1:10, 20))
table(mydata$xv1, mydata$xv2)
1 2 3 4 5 6 7 8 9 10
1 4 4 4 4 4 4 4 4 4 4
2 4 4 4 4 4 4 4 4 4 4
3 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4
5 4 4 4 4 4 4 4 4 4 4
I want tabulate again with yvar categories. The following is cutkey.
cutkey :
< 10 - group 1
10-12 - group 2
12-16 - group 3
>16 - group 4
Thus we will have similar to above type of table to each cutkey elements. I want to have margin sums everytime.
< 10 - group 1
1 2 3 4 5 6 7 8 9 10
1 4 4 4 4 4 4 4 4 4 4
2 4 4 4 4 4 4 4 4 4 4
3 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4
5 4 4 4 4 4 4 4 4 4 4
10-12 - group 2
1 2 3 4 5 6 7 8 9 10
1 4 4 4 4 4 4 4 4 4 4
2 4 4 4 4 4 4 4 4 4 4
3 4 4 4 4 4 4 4 4 4 4
4 4 4 4 4 4 4 4 4 4 4
5 4 4 4 4 4 4 4 4 4 4
and so on for all groups
(the numbers will be definately different)
Is there easyway to do it ?
Yes, using cut, dlply (plyr package) and addmargins:
mydata$yvar1 <- cut(mydata$yvar,breaks = c(-Inf,10,12,16,Inf))
> dlply(mydata,.(yvar1),function(x) addmargins(table(x$xv1,x$xv2)))
$`(-Inf,10]`
1 2 3 4 5 6 7 8 9 10 Sum
1 0 0 0 0 0 0 2 0 1 0 3
2 1 1 0 1 0 0 0 0 2 0 5
3 0 1 0 0 1 1 0 2 0 0 5
4 0 0 2 0 1 1 0 1 0 0 5
5 0 1 1 0 1 1 1 0 0 2 7
Sum 1 3 3 1 3 3 3 3 3 2 25
$`(10,12]`
1 2 3 4 6 7 8 9 10 Sum
1 0 0 0 1 2 0 0 0 0 3
2 0 0 1 0 0 1 0 0 1 3
3 0 1 0 1 1 2 0 0 1 6
4 0 1 0 0 0 0 0 0 0 1
5 1 0 1 1 1 0 1 1 2 8
Sum 1 2 2 3 4 3 1 1 4 21
$`(12,16]`
1 2 3 4 5 6 7 8 9 10 Sum
1 2 3 1 1 1 2 0 3 0 2 15
2 0 1 0 1 3 3 2 0 0 1 11
3 3 1 3 1 0 0 0 2 4 1 15
4 3 2 1 2 2 0 1 1 4 1 17
5 3 1 1 2 0 1 1 1 1 0 11
Sum 11 8 6 7 6 6 4 7 9 5 69
$`(16, Inf]`
1 2 3 4 5 6 7 8 9 10 Sum
1 2 1 3 2 3 0 2 1 3 2 19
2 3 2 3 2 1 1 1 4 2 2 21
3 1 1 1 2 3 2 2 0 0 2 14
4 1 1 1 2 1 3 3 2 0 3 17
5 0 2 1 1 3 1 2 2 2 0 14
Sum 7 7 9 9 11 7 10 9 7 9 85
attr(,"split_type")
[1] "data.frame"
attr(,"split_labels")
yvar1
1 (-Inf,10]
2 (10,12]
3 (12,16]
4 (16, Inf]
You can adjust the breaks argument to cut to get the values just how you want them. (Although the margin sums you display in your question don't look like margin sums at all.)

Resources