Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotGradient cuts off original data #48

Closed
stephanJG opened this issue Jun 18, 2020 · 4 comments
Closed

plotGradient cuts off original data #48

stephanJG opened this issue Jun 18, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@stephanJG
Copy link

Hi,
I recently realized that the "plotGradient" function is cutting off original data. The problem is that the ylim is set to min and max of the predictions, not the original data.
Best
Jörg

plotGradient
plotGr

ggplot
image

@ovaskain
Copy link
Collaborator

ovaskain commented Jun 19, 2020 via email

@jarioksa
Copy link
Collaborator

@ovaskain : I'll do this. I haven't peeked at the code yet, but sounds pretty trivial a fix.

@jarioksa jarioksa self-assigned this Jun 19, 2020
@jarioksa jarioksa added the bug Something isn't working label Jun 19, 2020
jarioksa added a commit that referenced this issue Jun 23, 2020
jarioksa added a commit that referenced this issue Jun 23, 2020
@jarioksa
Copy link
Collaborator

It seems that the max was correctly set with data, but the line of code for setting min was just forgotten. Should be fixed with commit 91874d6.

@stephanJG
Copy link
Author

PS: as I have been ask for how to plot with ggplot here some code

#Percentiles used in calculation
p <- c(.025,.5,.975)#95%
p_names <- paste0(p*100)
p_funs <- map(p, ~partial(quantile, probs = .x, na.rm = TRUE)) %>%
set_names(nm = p_names)

#names
v_expV<-MODEL$covNames %>% .[-1]
df_CIs<-NULL

#loop over all exp vars
for (i in 1:length(v_expV)){
#gradients
grad<-constructGradient(
MODEL,
focalVariable = v_expV[i],
non.focalVariables = 2) #(2 = net effect)
#use gradient to make predictions
pred<-predict(
MODEL,Gradient = grad,expected = T) #(probit: expected = T)
#df with 1000 pred * 20 units of exp vars
predGrad<-pred %>%
#richness of all pred values (see line 53 in plotGradient function for CWM)
lapply(rowSums) %>%
#merge list elements to rows
rlist::list.rbind() %>% as_tibble()
#df with quantiles as cols
CIs<-predGrad %>%
pivot_longer(everything(),names_to = "grad",values_to = "pred") %>%
mutate(across(everything(),type.convert)) %>%
group_by(grad) %>%
summarise(across(everything(),p_funs)) %>%
select(-1) %>%
rename_with(~c("Qua_low","Qua_mid","Qua_high"))
#df with all exp vars
df_CIs<-CIs %>% add_column(covNames=v_expV[i],.before = 1) %>%
bind_rows(df_CIs)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants